The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    1
    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:
    255
    Likes Received:
    2
    Trophy Points:
    18
    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:
    1
    Location:
    Rosario, Santa Fe, Argentina
    Re: Check a PHP CLI process is running (solved)

    Thank very much!
     
Loading...

Share This Page