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

  • Home
  • SEARCH
  • 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 8702501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:40:17+00:00 2026-06-13T02:40:17+00:00

I’m a PHP developer, and know very little about shell scripting… So I appreciate

  • 0

I’m a PHP developer, and know very little about shell scripting… So I appreciate any help here.

I have four php scripts that I need running in the background on my server. I can launch them just fine – they work just fine – and I can kill them by looking up their PID.

The problem is I need my script to, from time to time, kill the processes and restart them, as they maintain long standing HTTP requests that sometimes are ended by the other side.

But I don’t know how to write a command that’ll find these processes and kill them without looking up the PID manually.

We’ll start with one launch command :

/usr/local/php5/bin/php -f /home/path/to/php_script.php > /dev/null &

Is there a way to “assign” a PID so it’s always the same? or give the process a name? and how would I go about writing that new command?

Thank you!

  • 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-13T02:40:18+00:00Added an answer on June 13, 2026 at 2:40 am

    Nope, you can’t “assign” the process PID; instead, you should do as “real” daemons do: make your script save its own PID in some file, and then read it from that file when you need to kill.

    Alternative would be to use something like supervisor, that handles all that for you in a quite nice way.

    Update – supervisor configuration

    Since I mentioned supervisor, I’m also posting here a short supervisor configuration file that should do the job.

    [program:yourscriptname]
    command=/usr/local/php5/bin/php -f /home/path/to/php_script.php
    

    Have a look here for more configuration options.

    Then you can use it like this:

    # supervisorctl status
    

    to show the process(es) status.

    # supervisorctl start yourscriptname
    

    to start your script

    # supervisorctl stop yourscriptname
    

    to stop your script

    Update – real world supervisor configuration example

    First of all, make sure you have this in your /etc/supervisor/supervisord.conf.

    [include]
    files = /etc/supervisor/conf.d/*.conf
    

    if not, just add those two lines and

    mkdir /etc/supervisor/conf.d/
    

    Then, create a configurtion file for each process you want to launch:

    /etc/supervisor/conf.d/script1.conf

    [program:script1]
    command=/usr/local/php5/bin/php -f /home/path/to/php_script.php
    stdout_logfile=/var/log/script1.log
    stderr_logfile=/var/log/script1-error.log
    

    /etc/supervisor/conf.d/script2.conf

    [program:script2]
    command=/usr/local/php5/bin/php -f /home/path/to/php_script2.php
    stdout_logfile=/var/log/script2.log
    stderr_logfile=/var/log/script2-error.log
    

    …etc, etc.. for all your scripts.

    (note that you don’t need the trailing & as supervisor will handle all the daemonization thing for you; in fact you shouldn’t execute programs that are self-daemonizing inside supervisor).

    Then you can start ’em all with:

    supervisorctl start all
    

    or just one with something like:

    supervisorctl start script1
    

    Starting supervisor from php

    Of course, you can start/stop the supervisor-controlled processes using the two commands above, even from inside a script.

    Remember however that you’ll need root privileges, and it’s quite risky to allow eg. a web page to execute commands as root on the server..

    If that’s the case, I recommend you have a look at the instructions on how to run supervisor as a normal user (I never did that, but you should be able to run it as the www-data user too..).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.