Are you by any chance doing something like this?

while (1)
{
 $dbh = mysql_connect(x, x, x);
 mysql_query(...);
 sleep(10);
}

If so, you could run into that maxclients problem very quickly because you're not closing those mysql connections (they'll time out eventually, and there are persistent connection options in php.ini), but as you're only running one thread, you should never really have more than one connection open at a time - a well-placed mysql_close() may do wonders

Of course, that's just a guess as to how your script might be executing

If it really matters to you, you can get a cron job to execute (I think) every second, which would probably be a better solution

Or http://uk.php.net/manual/en/features.persistent-connections.php might have some useful info - I don't know because I haven't taken the time to read it :)

Cheers

Chris

Stephen Craton wrote:

i haven't paid a lot of attention to your setup. are you running this through your web server or via the php-cli?



Basically I have a file that connects to a database, before the loop, and then checks the database for new messages. If there are, it displays them accordingly



if via php through the web server i suspect you're running into a "maxclients" problem (your client connections aren't closing fast enough so you're using up all the client connections).



I was thinking this could be the case. Is there any way not to use up maxclients? I'm just running one loop, though it may be infinite.



if you're running this through your web server, a much more efficient approach would be via a php-cli or perl application. either of these should be able to run as continuous tasks without causing other problems.



I would run through command line but I'm not sure how. This is a chat script anyway, and I'm not sure if I have command line abilities on my production server.

Also, I was thinking of maybe using a socket server. Are socket servers
allowed by mainstream web hosts or do you need certain privileges to open a
socket and connect to them?

Thanks,
Stephen Craton






-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to