PDA

View Full Version : fsockopen in PHP


whiteseal
06-10-03, 10:13 PM
Hello All,

I have a scenerio:

I want to create 2 HTML frames Frame 1 and Frame 2.


Frame 1 has PHP codes to make a connection to a server but never close the socket thus the page would still be getting data and print to the screen like:

<?
ignore_user_abort(true);
set_time_limit(0);

$nick = "MyNick123";

$fp = stream_socket_client("tcp://irc.choopa.net:6667", $errno, $errstr,30);
if (!$fp) {
echo "$errstr ($errno)<br>\n";
} else {
fputs ($fp, "user a b c d\nnick $nick\n");
while ($fp && !feof($fp)){
$c = fgets ($fp,1024);
if (eregi("PING",$c)) {
$c = str_replace("PING","PONG",$c);
fputs($fp,"$c\n");
} else if (eregi("376 $nick",$c)) {
fputs($fp,"join #php\n");
}
echo "$c\n";
flush();
}
}
?>


In Frame 2, I want to be able to send data to $fp as you can see above.


My question is how can I set $fp in PHP SESSIONS and be able to call again using another php page.

Note that Frame 1 has a persistent connection... and $fp is still alive.


Anyone can help is much appreciated.

WhiteSeal

phpkid
06-11-03, 01:27 AM
Not possible.

You can not mimick something like 'Connection Pooling' for database with sockets because once your HTTP request is complete, PHP will automatically close the socket, if you havent done that already.

Regards,
JD