Solved

How to terminate child using proc_close()

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Why do people dis php? 5 50
Download tables into separate sheets 3 28
php string detection problem 7 34
how to use Initialization Vector for openssl_encrypt() 5 26
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
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…

777 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