Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:41:45+00:00 2026-06-09T02:41:45+00:00

So this is as much a theoretical question as a language-specific one, but consider

  • 0

So this is as much a theoretical question as a language-specific one, but consider this:

I need PHP to execute a rather system-intensive process (using PHP exec();) that will be running in the background, but then when a user leaves that specific page, the process will be killed.

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:

if($_SERVER['REQUEST_URI'] !== 'page_with_session.php'){
    //Instead of 'session_destroy();' this would be used to kill said process
}

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.

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:

  1. Page is hit by user
  2. <?php exec('killer.py') ?>
  3. killer.py:
    1. Listen for 20 seconds – If no response…
    2. os.system('pkill process')
  4. <?php while(true){sleep(15); exec('killer.py no_wait_dont');} ?>

Any thoughts you guys have would be greatly appreciated!

Mason

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:41:47+00:00Added an answer on June 9, 2026 at 2:41 am

    Javascript is a lot easier, and about as safe (that is, not much).

    Just write a javascript ping function that, once every 10 seconds, posts something to ping.php (via ajax). This ping.php would log when the last ping was received in the user session (say in $_SESSION['last_ping'])

    You can check for user activity from other pages by comparing $_SESSION['last_ping'] to the current time. You would have to pepper your runtime-intensive pages with this, but it would certainly work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this a theoretical question as much as practical. One has a table with,
This is a pretty-much theoretical question, but.. How much of an operating system could
This is a theoretical question as much as a practical one. I just can't
This is pretty much a duplicate question but instead of using Castle Dynamic Proxy
As I can't post code I'm asking this as a theoretical question, but giving
Important : Please see this very much related question: Return multiple values in C++
I have done this without much effort on T-SQL, but I want to implement
This is probably a noob question that I will get slated for but here
This is just a theoretical question. It was born from a real problem in
Disclaimer: This question is meant to be purely theoretical, so please don't ask me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.