Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aborting PHP scripts with infinite loops - URGENT

Status
Not open for further replies.

monkle

Programmer
Joined
Feb 11, 2004
Messages
132
Location
US
Hello

I need to know if there is a way to kill a php script that is caught in an infinite loop after it has started. Somehow I missed incrementing in the loop before I started running it.

This is extremely urgent, as it is adding records to the database. I caught on when I realized that there were still lots of records in the database immediately after I deleted them

Yes, I feel like an idiot for missing this. I'm currently searching the web for any info on it, but if anyone knows of a way to do it, I would greatly appreciate it.
 
Usually PHP installations have a timeout for maximum script execution.
Please supply more details:
- OS
- do you have shell access?
- what database server?

You can check with phpinfo() what the max_eexecution_time is.
 
Windows 2000
I have complete access to the machine
MSSQL
 
So - is it that you want to stop the script now?
 
max_execution_time = 64000
 
yes, I would like to stop the script now
 
You have 2 options:
a) stop/restart the web server - this will certainly kill the script if it was invoked from a browser
b) stop MSSQL server - should make the script fail with an dberror

Your timeout allows 17.777 hrs of execution time
 
I've tried stopping the web server
 
Worst scenario is to kill the process through the Task Manager. First, however, I'd try to force the service down through Administrative Tools>Services
 
I've tried killing it through the task manager, and it returns "Access Denied". I am logged into the server as Administrator
 
If you're running PHP through a web server, severing the connection from the browser to the server should kill the script. On most browsers, hitting escape kills the connection.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I closed the browser that initiated the offending script
 
Help me help you....

I closed the browser that initiated the offending script, and that

did did not

kill the script.



How are you running PHP? As a ISAPI filter or as a CGI?

Have you tried stopping and restarting the web server?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I closed the browser that initiated the offending script, and that did not fix the problem.

I have tried stopping and restarting the web server, and that did not fix the problem

It is running as a cgi

Some of the urgency has abated, as I have written a second script to clean up after the first. Every 30 seconds, this new script deletes all of the offending data. If none of the offending records are found, the new script is set to terminate.

Worst case scenario: The first script runs for 17.777 hours before timing out, and the second script runs behind it cleaning up the mess until the mess is gone, then terminates itself. At least I won't run the HD full, and I don't have to keep manually deleting the records.

That said, I still want to figure out how to terminate offending scripts.
 
Problem completely solved

I renamed the table temporarily, and both scripts died.
 
Is this a plain CGI, or is your CGI script spawning another script which does the work?

How is the script accessing MSSQL? What PHP function-family are you using?

Is there any reason why you could not run PHP as an ISAPI filter?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
{b]sleipnir214[/b]

I find it quite amusing to see two threads next to each other where one is asking how to prevent timeout and the other how to kill something that does not timeout. The irony of life.
 
DRJ478:
I agree, I was rather amused when I noticed that earlier.

sleipner214:
This is just a plain cgi

I access the database with the built-in mssql functions, ex. mssql_query()

I don't know that there's a reason why I could not run php as an ISAPI filter.
 
monkle:
Maybe you and ruffy should compare notes.



I don't know why the script would continue to run when the web server is shut down. I've primarily run PHP with Apache on Linux.

But the way I figure it, if you're running PHP as an ISAPI filter, the script would have to shut down when the web server does.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top