Username: Posted April 19, 2011 Share Posted April 19, 2011 The following code does what I want it to, but after it's done doing it, it won't stop loading. I believe it is because of the while loops (while(1) { ... } and while($data = ...) { ... }). I need while($data = ...) to read the data from the fsockopen. Thanks in advance function ircConnect($server, $port, $channel, $nick, $pass, $name, $msg) { set_time_limit(15); //If we put set_time_limit(0), the page won't timeout and never stops loading (The script works, that I'm aware of) $fp = fsockopen($server, $port); if(!$fp) die($php_errormsg); if(empty($php_errormsg)) { $error = "None!"; } else { $error = $php_errormsg; } echo "<table border='1' bordercolor='#FFCC00' style='background-color:#FFFFCC' width='400' cellpadding='3' cellspacing='3'>"; echo "<tr><td>Server</td><td>Port</td><td>Channel</td><td>Nick</td><td>Password</td><td>Error</td></tr>"; echo "<tr><td>$server</td><td>$port</td><td>$channel</td><td>$nick</td><td>$pass</td><td>$error</td></tr>"; echo "</table>"; fputs($fp, "USER aBot testchan.org TestchanIRCBot :TheBot\n"); fputs($fp, "PASS $pass\n"); fputs($fp, "NICK $nick\n"); fputs($fp, "JOIN $channel\n"); fputs($fp, "PRIVMSG $channel :$msg, my name is $nick!\n"); while($data = fgets($fp, 128)) { $ex = explode(' ', $data); echo nl2br($data); flush(); if($ex[0] == "PING") fputs($fp, "PONG " . $ex[1] ."\n"); } } http://i.imgur.com/E6j79.jpg Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/ Share on other sites More sharing options...
blacknight Posted April 19, 2011 Share Posted April 19, 2011 add fclose($fp); to the end of your function after the while statement will close the connection.. Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203325 Share on other sites More sharing options...
Username: Posted April 19, 2011 Author Share Posted April 19, 2011 add fclose($fp); to the end of your function after the while statement will close the connection.. I already thought about that. I added it, and it had no effect. Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203330 Share on other sites More sharing options...
Username: Posted April 19, 2011 Author Share Posted April 19, 2011 Shamefully bumping (Is that even allowed?) I still haven't resolved my problem. Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203598 Share on other sites More sharing options...
drisate Posted April 19, 2011 Share Posted April 19, 2011 try using foreach(fgets($fp, 128) as $data) if you get the same result then the problem must come from the code calling your ircConnect() Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203604 Share on other sites More sharing options...
Username: Posted April 19, 2011 Author Share Posted April 19, 2011 try using foreach(fgets($fp, 128) as $data) if you get the same result then the problem must come from the code calling your ircConnect() Warning: Invalid argument supplied for foreach() in C:\wamp\www\phpIRC\common\functions\func.php on line 19 Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203616 Share on other sites More sharing options...
Username: Posted April 19, 2011 Author Share Posted April 19, 2011 try using foreach(fgets($fp, 128) as $data) if you get the same result then the problem must come from the code calling your ircConnect() Warning: Invalid argument supplied for foreach() in C:\wamp\www\phpIRC\common\functions\func.php on line 19 I replaced flush() with sleep(2) and it loaded faster, but about 3 lines of it was cut off EDIT: Meant to edit, could someone merge these [This one and the last one] posts please? Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203622 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 Try this: while($data = fgets($fp, 128) !== false) { Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1203830 Share on other sites More sharing options...
Username: Posted May 2, 2011 Author Share Posted May 2, 2011 Try this: while($data = fgets($fp, 128) !== false) { Still the same Quote Link to comment https://forums.phpfreaks.com/topic/234116-after-script-executes-it-still-continues-to-load/#findComment-1209306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.