Page 1 of 1

Problematic fsockopen snippet...

Posted: Thu Sep 15, 2005 4:39 am
by tomfra
I am using a PHP script that I did not write which uses this fsockopen snippet to do the workn in "background":

Code: Select all

$op = fsockopen($_SERVER['HTTP_HOST'], 80);
			if (!$op) {
			  echo "$errstr ($errno)<br>\n";
			} else {

				fputs($op, "GET ". $URL . "\r\n\r\n");
				if ($dispoutput) { while (!feof($op)) { echo fread($op, 1024); } }
				fclose($op);
			}
It works, but it does not seem to be reliable enough. I'll gladly replace it with CURL if it solves the reliability problem. Unfortunately, I have very little experience with CURL.

So the questions are:

Do you spot any possible problem with the above fsockopen code that could result in low reliability (I think it has something to do with incorrent connection closing but that could be pure speculation).

Do you know how to accomplish the same thing with CURL?

Thanks!

Tomas

Posted: Thu Sep 15, 2005 5:12 am
by timvw
The problem is not fsockopen.. But the pseudo HTTP that is sent to the webserver..

I'm pretty sure this code will result into problems if you have a webserver with different virtual hosts..

You could use something like:

Code: Select all

$data = file_get_contents('http://blah.com/foo');