Using fsockopen and fread (Zend Cert)
I have came across this during my Zend Cert study, can anyone advise?
Q: What is wrong with the following code snippet? Assume default configuration values apply.
Answers (Choose 1):
$fp = fsockopen('www.php.net', 80);
fwrite($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n");
$data = fread($fp, 8192);
The request is blocking and may cause fread() to hang
The HTTP request is malformed
This script should be re-written using fgets() instead of fread()
The request is non-blocking and fread() may miss the response
You cannot use fwrite() with fsockopen()
The request is missing its closing \r\n and as such is malformed.
Should there be a double \r\n at the end of the request?
fwrite($fp, "GET / HTTP/1.0\r\nHost: www.php.net\r\n\r\n");
Yes. This is what distinguishes the end of the request from a new line.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread