![]() |
![]() OCAU News - Wiki - QuickLinks - Pix - Sponsors |
|
|||||||
| Notices |
|
Sign up for a free OCAU account and this ad will go away! Search our forums with Google: |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Member
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
|
If I have a php script running an infinite loop (say
Code:
while (true)
{
mysql_query("delete * from table");
}
Thanks! |
|
|
|
| Join OCAU to remove this ad! |
|
|
#2 |
|
Member
Join Date: Feb 2006
Location: Adelaide
Posts: 94
|
The php script will keep on running till the maximum execution timelimit is hit, as defined in php.ini
(i.e. hitting stop ain't gonna stop it) |
|
|
|
|
|
#3 |
|
Member
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
|
No wonder I can't find that goddamned bug in my application! And I suspect my University's sys admin is not amused by the amount of resources my "background" script is taking up.
I always thought that the PHP script will terminate once the HTTP request for it is terminated Guess I was wrong.Thanks teegman! Is there a solution for this? Or should I just not run apps like this? |
|
|
|
|
|
#4 |
|
Member
Join Date: Feb 2006
Location: Adelaide
Posts: 94
|
What are you trying to do?
Running a mysql query in an infinite loop is extremely bad practice.. the solution is thinking about what you are trying to achieve and deriving a way of programming it that isn't going to totally kill the system's resources
|
|
|
|
|
|
#5 |
|
Member
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
|
I'm trying to do this: http://forums.overclockers.com.au/sh...d.php?t=594906
What basically happens is that I run a loop checking if the database has been updated with a new message, and if it has, send it to the user... Not sure how I'll implement that though, maybe I'll think about it a little bit more. Thanks though You've been most helpful
|
|
|
|
|
|
#6 |
|
Member
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
|
Oh yea, I do realize that how much easier this would be should it be written in Java rather than PHP since in Java you can have thread control, send one thread to sleep, and wake the other thread up as as you insert data into the database, but I'll see what can be done in PHP or if it even can be done
![]() Cheers. |
|
|
|
|
|
#7 |
|
Member
Join Date: Feb 2006
Location: Adelaide
Posts: 94
|
I wouldn't be thinking loops for something like this, what I'd be thinking is 'how do I know when the database will have new data that needs to be sent to the users?'. The simple answer is whenever the database is being updated. Presumably you have control of the code that is updating the database, so whenever anyone fires off an action that results in the database being updated, run whatever code you need to run to update the other users then. Did that make any sense?
oh and p.s., you trying the cometd stuff? |
|
|
|
|
|
#8 | ||
|
Member
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
|
Quote:
I know how to do that in Java, but looking through the PHP manual I couldnt' find how to do it. Unless I'm missing out something... Quote:
|
||
|
|
|
|
|
#9 |
|
Member
Join Date: Aug 2001
Location: melb
Posts: 5,116
|
basically the php script runs from beginning to end. Usually a HTTP request will start it, and it will terminate as the HTTP connection is closed.
If the script has an infinite loop, it will just keep running continously in the apache handler thread/process and the HTTP connection wont be closed (it might time out on the user side) I dont believe that the stop button on the browser sends a termination request, i dont believe the HTTP protocol has one of those. It just stops seeking a response. |
|
|
|
|
|
#10 |
|
Member
Join Date: Nov 2006
Posts: 604
|
As i understand it, all php code is executes on the server, and once that has been executed, it returns the HTML markup to the browser. So, therefore, the script is continually running, and no html is being sent to the browser...
Well, thats my understanding of it, please correct me if i'm wrong
__________________
Sam Carter: They built their own stargate? Daniel: Waaay smarter than us. Jack O'Neill: Ours is bigger. |
|
|
|
![]() |
| Bookmarks |
|
Sign up for a free OCAU account and this ad will go away! |
| Thread Tools | |
|
|