Solved

How to terminate child using proc_close()

Posted on 2004-10-13
2
445 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 250 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 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