Page 1 of 1

Fsockopen Issue

Posted: Wed Jun 30, 2010 6:19 am
by kirank
Hi,

I got one issue with php fsockopen function. I am running a script for 24 hours. It connects to a remote server on one port and send / receive data from the connection. But the connection automaticall close after 1 or 2 hours. The script runs in background from cli. I tried pfsockopen, but no use. How i can keep the connection alive for 24 hours to run.



Thanks

Re: Fsockopen Issue

Posted: Wed Jun 30, 2010 7:48 am
by Jade
You need to change your php.ini file for a longer default_socket_timeout. It looks like you can also change stream_set_timeout();

http://php.net/manual/en/function.fsockopen.php
http://www.php.net/manual/en/function.s ... imeout.php

Re: Fsockopen Issue

Posted: Thu Jul 01, 2010 1:16 am
by kirank
I think you are not gone through the issue in details
I heard the default_socket_timeout works only in connection establishment not the socket lifetime. Also stream_set_timeout is for controlling the time taken for read/write operation on a socket stream. What i need is, when i open one connection, it won't closed by php for a long time, ie for 24 hours. The connection will be active !

Re: Fsockopen Issue

Posted: Thu Jul 01, 2010 8:06 am
by Jade
I guess I'm not sure why you would want to open a socket using PHP that's going to be open 24 hours... seems like to me that would be something better done in another language. However I'm pretty sure the socket timeout is tied to the php.ini file somewhere.

Re: Fsockopen Issue

Posted: Thu Jul 01, 2010 6:56 pm
by kirank
I have the option to use PHP only. Sometime the connection exist for a long time, but sometime it is not..

Re: Fsockopen Issue

Posted: Fri Jul 02, 2010 8:47 am
by Jade
The only other thing I can think of would be putting your code in a loop that is constantly checking to see if the socket is open or not. If it finds the socket has been closed then it would need to create it again and proceed from there.