note 98915 deleted from function.fsockopen by cmb
| From: | cmb@php.net | Date: | Sun, 07 Jul 2019 07:59:46 +0000 |
| Subject: | note 98915 deleted from function.fsockopen by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211506@lists.php.net to get a copy of this message | ||
Note Submitter: ken at kenmclean dot com dot au
----
Make sure you don't use a double line break ("\r\n\r\n") during the middle of your
header, as it appears to end the header.
This means a \r\n\r\n before "Connection: close\r\n\r\n" will not correctly tell fsockopen
to close the request, leading to a max timeout error.
Some of the code on this page does this. It took me days to figure out. Example:
<?php
// Wrong:
fwrite($fp, "GET / HTTP/1.1\r\n");
fwrite($fp, "Host: php.net\r\n");
fwrite($fp, "User-Agent: example\r\n\r\n");
fwrite($fp, "Connection: Close\r\n\r\n");
// Right:
fwrite($fp, "GET / HTTP/1.1\r\n" );
fwrite($fp, "Host: php.net\r\n");
fwrite($fp, "User-Agent: example\r\n");
fwrite($fp, "Connection: Close\r\n\r\n");
?>