Overclockers Australia Forums

OCAU News - Wiki - QuickLinks - Pix - Sponsors  

Go Back   Overclockers Australia Forums > Software Topics > Programming & Software Development

Notices


Sign up for a free OCAU account and this ad will go away!
Search our forums with Google:
Reply
 
Thread Tools
Old 1st August 2007, 9:19 PM   #1
yihfeng Thread Starter
Member
 
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
Default Quick question -- OCAU please help

If I have a php script running an infinite loop (say

Code:
while (true)
{
    mysql_query("delete * from table");
}
and I load the script from a browser window. If I click on stop in the browser, does the script immediately terminate? Or will it still run in for a while before the server runs some clean up processes to clean it up?

Thanks!
yihfeng is offline   Reply With Quote

Join OCAU to remove this ad!
Old 1st August 2007, 9:30 PM   #2
teegman
Member
 
Join Date: Feb 2006
Location: Adelaide
Posts: 94
Default

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)
teegman is offline   Reply With Quote
Old 1st August 2007, 9:32 PM   #3
yihfeng Thread Starter
Member
 
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
Default

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?
yihfeng is offline   Reply With Quote
Old 1st August 2007, 9:40 PM   #4
teegman
Member
 
Join Date: Feb 2006
Location: Adelaide
Posts: 94
Default

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
teegman is offline   Reply With Quote
Old 1st August 2007, 10:04 PM   #5
yihfeng Thread Starter
Member
 
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
Default

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
yihfeng is offline   Reply With Quote
Old 1st August 2007, 10:05 PM   #6
yihfeng Thread Starter
Member
 
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
Default

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.
yihfeng is offline   Reply With Quote
Old 1st August 2007, 10:37 PM   #7
teegman
Member
 
Join Date: Feb 2006
Location: Adelaide
Posts: 94
Default

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?
teegman is offline   Reply With Quote
Old 1st August 2007, 10:44 PM   #8
yihfeng Thread Starter
Member
 
Join Date: Nov 2005
Location: Melbourne
Posts: 1,401
Default

Quote:
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?
Yes, and can that be done in PHP? How would one running script let another running script know that something has happened?

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:
oh and p.s., you trying the cometd stuff?
Yes!
yihfeng is offline   Reply With Quote
Old 1st August 2007, 11:14 PM   #9
mordy
Member
 
mordy's Avatar
 
Join Date: Aug 2001
Location: melb
Posts: 5,116
Default

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.
mordy is offline   Reply With Quote
Old 2nd August 2007, 12:12 PM   #10
effekt26
Member
 
effekt26's Avatar
 
Join Date: Nov 2006
Posts: 604
Default

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.
effekt26 is offline   Reply With Quote
Reply

Bookmarks

Sign up for a free OCAU account and this ad will go away!

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +10. The time now is 6:43 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd. -
OCAU is not responsible for the content of individual messages posted by others.
Other content copyright Overclockers Australia.
OCAU is hosted by Internode!