Keeping a socket open

I am using Ajax to write data to a socket using PHP
I wish to keep the socket open so that I can make repeated calls to my Ajax function without having to open the socket each time. It would appear that I need to use pfsockopen to open a persistent socket, but as well as the socket being persistent, the variable containing the resorce returned by the pfsockopen funtion to enable me to write and read to the socket on subsequent calls also needs to be persistent.
If the socket is opened in the script called by the Ajax function and the resource stored in a local variable, it will be lost when the script closes and so will not be available on subsequent calls.
If I attempt to save the resource in a session variable by using
session_start();
$_SESSION[“FP”] = pfsockopen(…
or if I open the socket on my main web page and attempt to pass the resource as a parameter in my Ajax call, the resource is converted to a string variable of the form ‘resource id #1’.
How can I preserve the resource for subsequent calls to my script, or is there any other way to achieve what I am attempting to do?

Sponsor our Newsletter | Privacy Policy | Terms of Service