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('example@abc.com','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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.