Jump to content

very confuse with fsockopen


prashcom

Recommended Posts

Hello friends,

 

I am in big problem and i need help from you guys...

 

My problem is i want to run a php file for forever....

 

I used fsockopen for this and its seems its working all fine but i think somehow i am doing somewhere silly mistake...

 

This is my code:

 

The file name is "list-items.php", same as what i am going to call again using this socket connection.

 

mail('[email protected]','hi','helllo');

sleep(5);

if($_SERVER['SERVER_ADDR'] != '127.0.0.1')

{

$socket = fsockopen("www.example.com", 80, $errno, $errstr, 10);

if (!$socket)

{

//echo "$errstr ($errno)<br />\n";

echo "Error in socket connection.............";

}

else

{

$out = "GET list-items.php HTTP/1.1\r\n";

$out .= "Host: www.example.com\r\n";

$out .= "Connection: Close\r\n\r\n";

if (fwrite($socket, $out) === FALSE)

{

echo "error.........";

}

fclose($socket);

}

}

 

I am really confuse after seeing the output of this code....

 

This code is opening lots of threads with same instance...

 

Will anyone pls tell me how this will work...

 

My only job is to open a file in php such a way so will call itself after performing the desired task, in every 2-3 second...

 

Is there anyway i can achive the task?

I think cron is not good as will not run in such frequently.... my server support atleast 2minute gap....

 

so i think socket can do this job but why this example opening multiple threads instead of only one socket connection?

Link to comment
https://forums.phpfreaks.com/topic/91143-very-confuse-with-fsockopen/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.