Re: [PHP] Infinate looping
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
Re: [PHP] Infinate looping
On Sun, 19 Sep 2004 11:20:01 -0500, Stephen Craton <[EMAIL PROTECTED]> wrote: Yes, I agree, if I were making a task to run every few minutes it would be easier, but that's not exactly what I'm doing. I'm more or less streaming content from the database to the end-user. It's basically a chat script that I'm running. I thought about setting up a socket, but I'm not sure if that's even aloud on the mainstream web hosts, or is it? Thanks, Stephen Craton Have the page auto-refresh periodically. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Infinate looping
> 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
RE: [PHP] Infinate looping
:: :: Personally, I think you're taking the wrong approach to solve your :: problem. PHP scripts were meant to execute in short fashion, to get :: over and done with. If you need something that checks for changes, :: don't make the PHP script run from now until doomsday, set it up as a :: scheduled task that runs every minute (or whatever interval you :: require). It's a much cleaner setup, and you're removing the :: webserver from the equation since you'll be running PHP from the :: command line. :: Yes, I agree, if I were making a task to run every few minutes it would be easier, but that's not exactly what I'm doing. I'm more or less streaming content from the database to the end-user. It's basically a chat script that I'm running. I thought about setting up a socket, but I'm not sure if that's even aloud on the mainstream web hosts, or is it? Thanks, Stephen Craton -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Infinate looping
On Sat, 18 Sep 2004 19:48:37 -0500, Stephen Craton <[EMAIL PROTECTED]> wrote: > Here's what I'm doing in a nutshell: Loop infinitely, checking for changes > to a database, flushing the data, sleep, and repeat the loop. It all goes > well and I'm getting it to work correctly. However, I'm not sure on the > impact on my webserver. Personally, I think you're taking the wrong approach to solve your problem. PHP scripts were meant to execute in short fashion, to get over and done with. If you need something that checks for changes, don't make the PHP script run from now until doomsday, set it up as a scheduled task that runs every minute (or whatever interval you require). It's a much cleaner setup, and you're removing the webserver from the equation since you'll be running PHP from the command line. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php