Fsockopen Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Fsockopen Issue

Post 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
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Fsockopen Issue

Post 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
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Re: Fsockopen Issue

Post 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 !
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Fsockopen Issue

Post 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.
kirank
Forum Newbie
Posts: 23
Joined: Thu Dec 03, 2009 2:19 am

Re: Fsockopen Issue

Post by kirank »

I have the option to use PHP only. Sometime the connection exist for a long time, but sometime it is not..
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: Fsockopen Issue

Post 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.
Post Reply