Jump to content

After script executes it still continues to load


Username:

Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.