RE: [PHP] socket_read can not read the whole HTTP page?
HTTP 1.1 requires more complex client/server interaction, and if your client (which is about as brain-dead simple as it gets) isn't doing that complex stuff, 1.1 will not work. All HTTP 1.1 servers will work just fine with 1.0, so stick with that unless you really NEED a feature of 1.1 On Fri, December 28, 2007 2:58 am, ked wrote: Wow, That's correct answer! Thank to Eddie Dunckley ! scheme: $in .= GET {$file} HTTP/1.0\r\n; //--- $in .= Accept: text/html\r\n; $in .= Accept-Language: zh-cn\r\n; $in .= User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727)\r\n; $in .= Host: {$host}\r\n; $in .= Cache-Control: no-cache\r\n; $in .= Connection: closed\r\n\r\n;//must be closed 1.must be HTTP/1.0 : why? IE post HTTP/1.1 . 2. must be closed : so that should be close not closed; Both modification are required. Shall anyone tell me sth. about HTTP/1.0 and HTTP/1.1 ? best regards! ked -Original Message- From: Eddie Dunckley [mailto:[EMAIL PROTECTED] Sent: Friday, December 28, 2007 3:50 PM To: php-general@lists.php.net Subject: Re: [PHP] socket_read can not read the whole HTTP page? On Fri 28 Dec 07, ked wrote: I wrote those script to get HTTP url content, and it works , but it can't read the whole content of the page. Blocked on while ($out = socket_read($socket, 1024)) . $in .= GET {$file} HTTP/1.1\r\n; try to change this to $in .= GET {$file} HTTP/1.0\r\n; $in .= Connection: Keep-Alive\r\n\r\n; and change this to $in .= Connection: closed\r\n\r\n; -- Eddie Dunckley - [EMAIL PROTECTED] - Realtime Travel Connections IBE Development, www.rttc.co.za, cell 083-379-6891, fax 086-617-7831 Where 33deg53'37.23S 18deg37'57.87E Cape Town Bellville Oakdale ZA Chaos, panic, and disorder - my work here is done. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a gift link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] socket_read can not read the whole HTTP page?
Wow, That's correct answer! Thank to Eddie Dunckley ! scheme: $in .= GET {$file} HTTP/1.0\r\n; //--- $in .= Accept: text/html\r\n; $in .= Accept-Language: zh-cn\r\n; $in .= User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 2.0.50727)\r\n; $in .= Host: {$host}\r\n; $in .= Cache-Control: no-cache\r\n; $in .= Connection: closed\r\n\r\n;//must be closed 1.must be HTTP/1.0 : why? IE post HTTP/1.1 . 2. must be closed : so that should be close not closed; Both modification are required. Shall anyone tell me sth. about HTTP/1.0 and HTTP/1.1 ? best regards! ked -Original Message- From: Eddie Dunckley [mailto:[EMAIL PROTECTED] Sent: Friday, December 28, 2007 3:50 PM To: php-general@lists.php.net Subject: Re: [PHP] socket_read can not read the whole HTTP page? On Fri 28 Dec 07, ked wrote: I wrote those script to get HTTP url content, and it works , but it can't read the whole content of the page. Blocked on while ($out = socket_read($socket, 1024)) . $in .= GET {$file} HTTP/1.1\r\n; try to change this to $in .= GET {$file} HTTP/1.0\r\n; $in .= Connection: Keep-Alive\r\n\r\n; and change this to $in .= Connection: closed\r\n\r\n; -- Eddie Dunckley - [EMAIL PROTECTED] - Realtime Travel Connections IBE Development, www.rttc.co.za, cell 083-379-6891, fax 086-617-7831 Where 33deg53'37.23S 18deg37'57.87E Cape Town Bellville Oakdale ZA Chaos, panic, and disorder - my work here is done. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read can not read the whole HTTP page?
On Fri 28 Dec 07, ked wrote: I wrote those script to get HTTP url content, and it works , but it can't read the whole content of the page. Blocked on while ($out = socket_read($socket, 1024)) . $in .= GET {$file} HTTP/1.1\r\n; try to change this to $in .= GET {$file} HTTP/1.0\r\n; $in .= Connection: Keep-Alive\r\n\r\n; and change this to $in .= Connection: closed\r\n\r\n; -- Eddie Dunckley - [EMAIL PROTECTED] - Realtime Travel Connections IBE Development, www.rttc.co.za, cell 083-379-6891, fax 086-617-7831 Where 33deg53'37.23S 18deg37'57.87E Cape Town Bellville Oakdale ZA Chaos, panic, and disorder - my work here is done. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read can not read the whole HTTP page?
On Fri 28 Dec 07, Eddie Dunckley wrote: On Fri 28 Dec 07, ked wrote: I wrote those script to get HTTP url content, and it works , but and change this to $in .= Connection: closed\r\n\r\n; soz that should be close not closed; -- Eddie - Chaos, panic, and disorder - my work here is done. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read
I want to read the content from a socket that is sending XML. IIRC, you just read in a loop while there's still stuff to read. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] socket_read
Check out some XML examples, maybe you can find more there : http://www.weberdev.com/AdvancedSearch.php?example=searchtype=categorysort =titlesearch=category=XMLdate=secondary=SearchIn=All+CategoriesIsSub= PHPFunctions=Articles=on Sincerely berber Visit the Weber Sites Today, To see where PHP might take you tomorrow. SEO Data Monitor : http://seo.weberdev.com PHP MySQL Forums : http://www.weberforums.com -Original Message- From: Peter Lauri [mailto:[EMAIL PROTECTED] Sent: Thursday, February 09, 2006 7:05 PM To: 'PHP General Users' Subject: [PHP] socket_read Best group member, I want to read the content from a socket that is sending XML. The socket_read(socket, length) takes the two parameters. But what I am concerned about it, I do not actually know the 'length' of what is being sent. How do I protect myself from that? Right now I just use a value of 'length' that with margin is larger then the size I will receive. Is it possible to get the size of what is ready to be read from the socket? Best regards, Peter Lauri -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read() trouble with PHP_BINARY_READ
Hi, Saturday, September 3, 2005, 9:19:11 AM, you wrote: MS hello, MS I'm writing a socket approach to send email directly via an SMTP server MS (since some hosts block sendmail trough php due to abuse). Now, I have MS the code, attached below: MS I have cut it down slightly so it would still be readable though. I'm MS very sure that none of the stuff I removed actually matters in the MS problem though (mostly error chechking, logging, debug stuff, etc). MS Ok, back to the problem. If I reread my log, I see the following output: MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2) MS C: HELO ip MS S: MS C: MAIL FROM: [EMAIL PROTECTED] MS S: 250 server OK, server2 [ip]. MS C: RCPT TO: [EMAIL PROTECTED] MS S: MS C: RSET MS Now, obviously, the server sends something back (I checked, manually, MS using telnet). So, I figured that the socket_read(socket, size, MS PHP_NORMAL_READ) was causing the problem. So I switched over to MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke MS off eg. midways). So... after I changed that, I suddenly started getting MS these errors: MS Warning: socket_read() unable to read from socket [11]: Resource MS temporarily unavailable in /home/me/scripts/mail.php on line 27 MS This goes for each attempt to read (even the first). I'm stumped... and MS really don't know how to proceed now... MS Does anyone have any clues? MS very appreciated, Because of this line the function returns straight away. MS socket_set_nonblock($this-socket); You have to catch the 'not ready' error something like this: (The error code was under windows) function get(){ $ret = ''; while(1){ $sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ); if(false === $sbuf){ $error = socket_last_error($this-connection); if($error != 10035){ echo msgsock read() failed: reason: .$error.' '. socket_strerror (socket_last_error($this-connection)) . \n; return;//socket not happy } }else{ $buf_read = strlen($sbuf); if($buf_read === 0) break; // end of text $ret .= $sbuf; } } return $ret; } -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read() trouble with PHP_BINARY_READ
hello, thank you for the help, but I've tried your code, and it returns the exact same thing :( the error #11 temporarily unavailable. If I remove non-blocking, or change the error to ignore to 11 (10035 in your code example) it simply hangs doing nothing *at all*... I'm stumped; really.. thank you for trying though :) - tul Tom Rogers wrote: Hi, Saturday, September 3, 2005, 9:19:11 AM, you wrote: MS hello, MS I'm writing a socket approach to send email directly via an SMTP server MS (since some hosts block sendmail trough php due to abuse). Now, I have MS the code, attached below: MS I have cut it down slightly so it would still be readable though. I'm MS very sure that none of the stuff I removed actually matters in the MS problem though (mostly error chechking, logging, debug stuff, etc). MS Ok, back to the problem. If I reread my log, I see the following output: MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2) MS C: HELO ip MS S: MS C: MAIL FROM: [EMAIL PROTECTED] MS S: 250 server OK, server2 [ip]. MS C: RCPT TO: [EMAIL PROTECTED] MS S: MS C: RSET MS Now, obviously, the server sends something back (I checked, manually, MS using telnet). So, I figured that the socket_read(socket, size, MS PHP_NORMAL_READ) was causing the problem. So I switched over to MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke MS off eg. midways). So... after I changed that, I suddenly started getting MS these errors: MS Warning: socket_read() unable to read from socket [11]: Resource MS temporarily unavailable in /home/me/scripts/mail.php on line 27 MS This goes for each attempt to read (even the first). I'm stumped... and MS really don't know how to proceed now... MS Does anyone have any clues? MS very appreciated, Because of this line the function returns straight away. MS socket_set_nonblock($this-socket); You have to catch the 'not ready' error something like this: (The error code was under windows) function get(){ $ret = ''; while(1){ $sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ); if(false === $sbuf){ $error = socket_last_error($this-connection); if($error != 10035){ echo msgsock read() failed: reason: .$error.' '. socket_strerror (socket_last_error($this-connection)) . \n; return;//socket not happy } }else{ $buf_read = strlen($sbuf); if($buf_read === 0) break; // end of text $ret .= $sbuf; } } return $ret; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read() trouble with PHP_BINARY_READ
Hi there! Can't it be anything with filepermissions? Just a clue... /G @varupiraten.se - Original Message - From: M. Sokolewicz [EMAIL PROTECTED] To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED] Sent: Saturday, September 03, 2005 10:49 AM Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ hello, thank you for the help, but I've tried your code, and it returns the exact same thing :( the error #11 temporarily unavailable. If I remove non-blocking, or change the error to ignore to 11 (10035 in your code example) it simply hangs doing nothing *at all*... I'm stumped; really.. thank you for trying though :) - tul Tom Rogers wrote: Hi, Saturday, September 3, 2005, 9:19:11 AM, you wrote: MS hello, MS I'm writing a socket approach to send email directly via an SMTP server MS (since some hosts block sendmail trough php due to abuse). Now, I have MS the code, attached below: MS I have cut it down slightly so it would still be readable though. I'm MS very sure that none of the stuff I removed actually matters in the MS problem though (mostly error chechking, logging, debug stuff, etc). MS Ok, back to the problem. If I reread my log, I see the following output: MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2) MS C: HELO ip MS S: MS C: MAIL FROM: [EMAIL PROTECTED] MS S: 250 server OK, server2 [ip]. MS C: RCPT TO: [EMAIL PROTECTED] MS S: MS C: RSET MS Now, obviously, the server sends something back (I checked, manually, MS using telnet). So, I figured that the socket_read(socket, size, MS PHP_NORMAL_READ) was causing the problem. So I switched over to MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke MS off eg. midways). So... after I changed that, I suddenly started getting MS these errors: MS Warning: socket_read() unable to read from socket [11]: Resource MS temporarily unavailable in /home/me/scripts/mail.php on line 27 MS This goes for each attempt to read (even the first). I'm stumped... and MS really don't know how to proceed now... MS Does anyone have any clues? MS very appreciated, Because of this line the function returns straight away. MS socket_set_nonblock($this-socket); You have to catch the 'not ready' error something like this: (The error code was under windows) function get(){ $ret = ''; while(1){ $sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ); if(false === $sbuf){ $error = socket_last_error($this-connection); if($error != 10035){ echo msgsock read() failed: reason: .$error.' '. socket_strerror (socket_last_error($this-connection)) . \n; return;//socket not happy } }else{ $buf_read = strlen($sbuf); if($buf_read === 0) break; // end of text $ret .= $sbuf; } } return $ret; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 2005-09-02 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read() trouble with PHP_BINARY_READ
file permissions on what? These are sockets :( - tul As the wise Gustav Wiberg [EMAIL PROTECTED] said: Hi there! Can't it be anything with filepermissions? Just a clue... /G @varupiraten.se - Original Message - From: M. Sokolewicz [EMAIL PROTECTED] To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED] Sent: Saturday, September 03, 2005 10:49 AM Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ hello, thank you for the help, but I've tried your code, and it returns the exact same thing :( the error #11 temporarily unavailable. If I remove non-blocking, or change the error to ignore to 11 (10035 in your code example) it simply hangs doing nothing *at all*... I'm stumped; really.. thank you for trying though :) - tul Tom Rogers wrote: Hi, Saturday, September 3, 2005, 9:19:11 AM, you wrote: MS hello, MS I'm writing a socket approach to send email directly via an SMTP server MS (since some hosts block sendmail trough php due to abuse). Now, I have MS the code, attached below: MS I have cut it down slightly so it would still be readable though. I'm MS very sure that none of the stuff I removed actually matters in the MS problem though (mostly error chechking, logging, debug stuff, etc). MS Ok, back to the problem. If I reread my log, I see the following output: MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2) MS C: HELO ip MS S: MS C: MAIL FROM: [EMAIL PROTECTED] MS S: 250 server OK, server2 [ip]. MS C: RCPT TO: [EMAIL PROTECTED] MS S: MS C: RSET MS Now, obviously, the server sends something back (I checked, manually, MS using telnet). So, I figured that the socket_read(socket, size, MS PHP_NORMAL_READ) was causing the problem. So I switched over to MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke MS off eg. midways). So... after I changed that, I suddenly started getting MS these errors: MS Warning: socket_read() unable to read from socket [11]: Resource MS temporarily unavailable in /home/me/scripts/mail.php on line 27 MS This goes for each attempt to read (even the first). I'm stumped... and MS really don't know how to proceed now... MS Does anyone have any clues? MS very appreciated, Because of this line the function returns straight away. MS socket_set_nonblock($this-socket); You have to catch the 'not ready' error something like this: (The error code was under windows) function get(){ $ret = ''; while(1){ $sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ); if(false === $sbuf){ $error = socket_last_error($this-connection); if($error != 10035){ echo msgsock read() failed: reason: .$error.' '. socket_strerror (socket_last_error($this-connection)) . \n; return;//socket not happy } }else{ $buf_read = strlen($sbuf); if($buf_read === 0) break; // end of text $ret .= $sbuf; } } return $ret; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 2005-09-02 -- Tularis XMB Developer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] socket_read() trouble with PHP_BINARY_READ
In the end I decided I'll just use the fsockopen(), feof(), fwrite, fread, etc. function-set instead (got the idea from PEAR's NET_Socket). And that seems to work just fine... too bad I couldn't get the low-level functions to work (still don't know why), but this works great... thank you all for the help/support though! - tul M. Sokolewicz wrote: file permissions on what? These are sockets :( - tul As the wise Gustav Wiberg [EMAIL PROTECTED] said: Hi there! Can't it be anything with filepermissions? Just a clue... /G @varupiraten.se - Original Message - From: M. Sokolewicz [EMAIL PROTECTED] To: php-general@lists.php.net; Tom Rogers [EMAIL PROTECTED] Sent: Saturday, September 03, 2005 10:49 AM Subject: Re: [PHP] socket_read() trouble with PHP_BINARY_READ hello, thank you for the help, but I've tried your code, and it returns the exact same thing :( the error #11 temporarily unavailable. If I remove non-blocking, or change the error to ignore to 11 (10035 in your code example) it simply hangs doing nothing *at all*... I'm stumped; really.. thank you for trying though :) - tul Tom Rogers wrote: Hi, Saturday, September 3, 2005, 9:19:11 AM, you wrote: MS hello, MS I'm writing a socket approach to send email directly via an SMTP server MS (since some hosts block sendmail trough php due to abuse). Now, I have MS the code, attached below: MS I have cut it down slightly so it would still be readable though. I'm MS very sure that none of the stuff I removed actually matters in the MS problem though (mostly error chechking, logging, debug stuff, etc). MS Ok, back to the problem. If I reread my log, I see the following output: MS S: 220 server -- Server ESMTP (iPlanet Messaging Server 5.2) MS C: HELO ip MS S: MS C: MAIL FROM: [EMAIL PROTECTED] MS S: 250 server OK, server2 [ip]. MS C: RCPT TO: [EMAIL PROTECTED] MS S: MS C: RSET MS Now, obviously, the server sends something back (I checked, manually, MS using telnet). So, I figured that the socket_read(socket, size, MS PHP_NORMAL_READ) was causing the problem. So I switched over to MS PHP_BINARY_READ to make sure I didn't miss anything (because it broke MS off eg. midways). So... after I changed that, I suddenly started getting MS these errors: MS Warning: socket_read() unable to read from socket [11]: Resource MS temporarily unavailable in /home/me/scripts/mail.php on line 27 MS This goes for each attempt to read (even the first). I'm stumped... and MS really don't know how to proceed now... MS Does anyone have any clues? MS very appreciated, Because of this line the function returns straight away. MS socket_set_nonblock($this-socket); You have to catch the 'not ready' error something like this: (The error code was under windows) function get(){ $ret = ''; while(1){ $sbuf = @socket_read($this-connection, 1024, PHP_BINARY_READ); if(false === $sbuf){ $error = socket_last_error($this-connection); if($error != 10035){ echo msgsock read() failed: reason: .$error.' '. socket_strerror (socket_last_error($this-connection)) . \n; return;//socket not happy } }else{ $buf_read = strlen($sbuf); if($buf_read === 0) break; // end of text $ret .= $sbuf; } } return $ret; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.10.18/89 - Release Date: 2005-09-02 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php