Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to terminate child using proc_close()

Posted on 2004-10-13
2
Medium Priority
?
511 Views
Last Modified: 2012-05-05
I made a php script that calls a python program using proc_open, but sometimes the python script takes a very long time to finish. I have therefore registered a shutdown function (using register_shutdown_function()) that is callled when the user hits the stop button on their browser. This shutdown function closes the python script using proc_close().

However, this doesn't *always* work, and I'm often left with several CPU-hogging python scripts running at the end of the day, making my web application extremenly slow.

From the PHP documentation (http://us2.php.net/manual/en/function.proc-close.php), I gather that proc_close 'waits for the process to terminate'. What I want to do is close the process immediately, the equivalent of using 'kill -KILL' on the command line. Does anyone know how to do that?

Is there a way to determine the process id (PID) of the child, so that I can execute a shell command using escapeshellcmd() that explicitally calls 'kill -KILL'?

Thanks.
0
Comment
Question by:vladc6
2 Comments
 
LVL 14

Accepted Solution

by:
ThG earned 750 total points
ID: 12303358
You mean that proc_close() never terminates the spawned process? This is disappointing if it's true. Can you try with popen()? It allows only uni-directional stream (so read OR write to the process).

Otherwise, you should obtain that process' PID and manually system("kill -9 process_pid");
0
 

Author Comment

by:vladc6
ID: 12310705
Right, apparently proc_close() can't force termination. Nevertheless, as of PHP 5.0, a new function called proc_terminate() does that. Here's the manual for proc_terminate():
http://us2.php.net/manual/en/function.proc-terminate.php

Just goes to show how fast PHP development is going, and how gaps are starting to fill!

Thanks, ThG - I've accepteed your response.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question