?
Solved

How to terminate child using proc_close()

Posted on 2004-10-13
2
Medium Priority
?
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

718 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