Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Check a PHP CLI process is running

Discussion in 'General Discussion' started by mozart_ar, Jan 10, 2011.

  1. mozart_ar

    mozart_ar Registered

    Joined:
    Jan 17, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Rosario, Santa Fe, Argentina
    Check if a PHP CLI process is running

    Hello,
    I have a custom PHP script that open a UDP for listening incomming connection. I need this process be always active.
    Is there a way to do this with chkservd or tailwatch?

    The process is initiated from /etc/rc.local , this way:

    sudo -u {user} /usr/local/bin/php -f /home/path/to/script.php > /dev/null &

    Regards,
    -Walter
     
    #1 mozart_ar, Jan 10, 2011
    Last edited: Jan 10, 2011
  2. InterServed

    InterServed Well-Known Member

    Joined:
    Jul 10, 2007
    Messages:
    261
    Likes Received:
    4
    Trophy Points:
    68
    cPanel Access Level:
    DataCenter Provider
    You may do a bash script and setup a cron for the script:

    Code:
    #!/bin/bash
    ###########################################
    script_path=/home/path/to/script.php
    process_check=`lsof|grep $script_path|wc -l`
    ###########################################
    
    if [ $process_check -ge "1" ] then
    exit 0;
    else
    #your start command for your script
    sudo -u {user} /usr/local/bin/php -f $script_path > /dev/null &
    fi
     
  3. mozart_ar

    mozart_ar Registered

    Joined:
    Jan 17, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    51
    Location:
    Rosario, Santa Fe, Argentina
    Re: Check a PHP CLI process is running (solved)

    Thank very much!
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice