views:

569

answers:

2

Hello all,

I make lots of GET requests to several PHP scripts via AJAX. I want to ask for implementation advice on how to kill a PHP script that is currently running (in the background).

Is there some way to get the PHP scripts process ID when it runs and then I can probably kill that process via shell/cmd etc?

Is there a better way?

Thanks all

+1  A: 

Whether PHP is a process of its own at all will depend on how PHP and web server are configured. But even when it is, it is going to be awfully hard to catch the correct PHP process to kill.

If you know inside your PHP script that this is the process that needs killing, you may be able to use getmypid() or find something in the User Contributed Notes there.

I still don't entirely understand the situation. Why do you need to kill them at all?

Pekka
Say a very long process is running (several hours) - and you remember you haven't set a config variables correctly, then it will be handy to kill this process which in my case includes killing all PHP scripts, all SQL Server instances, other external programs etc.
Abs
You are right, this may be a problem for me as I am running PHP as an Apache module - having looked at my tasklist, I can only see httpd.exe running.
Abs
Won't restarting the server do the job? Maybe setting up one or several virtual machines that can be restarted independently are the right thing for you?
Pekka
I think this may be the only solution for me. Thanks Pekka! :)
Abs
A: 

I did not exactly get, what you are trying to do, but I think you might have reached a part of the web stack that is a dead end. If you are making a lot of ajax requests, you will definitely kill your server, because it cannot handle an "infinite" amount of connections.

I think you might have to rethink your architecture. You might want to read into COMET and long polling.

FlorianH
I only make 5/6 AJAX requests and have about 5/6 scripts running at the same time. This isn't the number of PHP scripts running at the same time problem!
Abs