PHP Chat Bot loses connection after about 10 minutes

Hi, I have a very basic chatbot which can connect to the chat and read messages (that’s actually all I want). But after about 10 min the socket just stops responding. I am sending a correct “Pong” everytime the server sends a “ping”. So that shouldn’t be the issue. Does anyone have an idea?

Here is the code I am using:

ini_set('max_execution_time', '21600');

$chan = "#[mychannel]";
$server = "";
$port = 6667;
$nick = "[mynick]";
$pass = "oauth:[my oauth]";

$socket = fsockopen($server, $port,$errno,$errstr,15);
stream_set_timeout($socket, 21600);
fwrite($socket,"PASS ".$pass."\r\n");
fwrite($socket,"NICK ".$nick."\r\n"); 
fwrite($socket,"JOIN ".$chan."\r\n");

while(1) {
	while($data = fgets($socket,256)) {
	    // do stuff like reading and interpreting messages
	    // end stuff
        $ping = explode(' ', $data);
        if($ping[0] == 'PING'){
            fputs($socket, 'PONG '.$ping[1].'\r\n');

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.