Solved

How to terminate child using proc_close()

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now