Note that there are some explanatory texts on larger screens.

plurals
  1. PODead Man's Switch in PHP/Python
    primarykey
    data
    text
    <p>So this is as much a theoretical question as a language-specific one, but consider this:</p> <p>I need PHP to execute a rather system-intensive process (using PHP <code>exec();</code>) that will be running in the background, but then when a user leaves that specific page, the process will be killed. </p> <p>I quickly realized that a dead man's switch would be an easy way to implement this since I'm not making use of any session variables or other server-side variables, which could end up looking like:</p> <pre><code>if($_SERVER['REQUEST_URI'] !== 'page_with_session.php'){ //Instead of 'session_destroy();' this would be used to kill said process } </code></pre> <p>In any case, a while loop in PHP, resetting a timer in a Python script or re-calling said script every 15 seconds so that it doesn't get to the end and kill the process. However, when the user leaves the page, the script will have been called but not able to reset before killing the process.</p> <p>Are there any gaping holes in this idea? If not, how would the implementation in PHP/JS look? The order I see it working in would be:</p> <ol> <li>Page is hit by user</li> <li><code>&lt;?php exec('killer.py') ?&gt;</code></li> <li>killer.py: <ol> <li>Listen for 20 seconds - If no response...</li> <li><code>os.system('pkill process')</code></li> </ol></li> <li><code>&lt;?php while(true){sleep(15); exec('killer.py no_wait_dont');} ?&gt;</code></li> </ol> <p>Any thoughts you guys have would be greatly appreciated!</p> <p>Mason</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload