-
July 10th, 2008, 10:57 AM
#1
PHP socket keep alive.
How to keep alive Socket in php? On user command disconnect?
Senario 1:
Client=======Server
1. Connect send
--------------->
2. Ack Recv
<---------------
3. Echo/Primitive
--------------->
4. hh:mm minute
processing....
----------------
5. Status recv
<---------------
6. New command
---------------->
7. Close on request
---------------->
PHP Code:
// Send Raw data over TCP
$fp = fsockopen ('212.58.58.58',5400, $errno, $errstr, 30);
if (!$fp) {
// Error
} else {
// 1st primitive
fwrite($fp,$sends); //fixed
echo hex4str (fread ($fp,256)); //read for debug
// On recv data
// close this session on command not automatic.
fclose($fp);
}
Last edited by PeejAvery; July 10th, 2008 at 12:36 PM.
Reason: Added PHP tags.
-
July 10th, 2008, 12:39 PM
#2
Re: PHP socket keep alive.
In you PHP configuration file (php.ini is the default), change default_socket_timeout to a very large number of seconds. The default is 60.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 11th, 2008, 01:57 AM
#3
Re: PHP socket keep alive.
This is increasing the auto connection close session lenght. But in client browser will this be real time send/recv processes ?
-
July 11th, 2008, 02:01 AM
#4
Re: PHP socket keep alive.
I would suggest instead of changing the default settings of the php.ini file, can i use ini_set() function which can be defined my page code. All i then do is change it to a really long amount of seconds, atleast the connection will not close, and then trying web page send/recv commands.
ini_set( 'default_socket_timeout', xxxxx);
what do you suggest?
-
July 11th, 2008, 06:53 AM
#5
Re: PHP socket keep alive.
The setting is for the server. If you set it for 15 minutes, there is no way anyone is going to sit there and let your page go for that long. In essence, it would be like the connection never closes for the client.
You can use ini_set(), but be aware of some server settings. If this is a hosted server from some company, most likely, you will not be able to alter the configuration using ini_set(). Instead, if you sign in to the account, they usually have a way to change the configuration file.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
July 11th, 2008, 12:02 PM
#6
Re: PHP socket keep alive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|