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
Fsockopen Issue
Moderator: General Moderators
Re: Fsockopen Issue
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
http://php.net/manual/en/function.fsockopen.php
http://www.php.net/manual/en/function.s ... imeout.php
Re: Fsockopen Issue
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 !
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
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
I have the option to use PHP only. Sometime the connection exist for a long time, but sometime it is not..
Re: Fsockopen Issue
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.