PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 14, 2022

[FIXED] How to kill a web process

 January 14, 2022     lamp, linux, php     No comments   

Issue

I have a web script that takes a really long time to run (and it's supposed to take a long time). By "web script" I mean a script that's run by visiting a page in a browser and opposed to executed on the command line. The script is in PHP and I'm on a LAMP stack.

How can I find and kill this process if I want to?

"Kill" might be the wrong word. I just want the script to stop. I could conceivably make this script "watch" for some state of my system to change, and then halt when it notices that change. If I do that, I'm not sure what the best way to do that would be. In any case, I'm completely open to any suggestions.


Solution

When the script starts, write its pid to a file, something like

 file_put_contents(getmypid ().".pid","Running");

And when the script is done, it deletes the file.

You then create another script that will run form cron. It looks for pid files over a certain age, and does a kill $pid on them

Simple.



Answered By - Byron Whitlock
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing