[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

PHP script determine if running a daemon or console

I have a php script that I can either run from the command line or as a Linux daemon.  I would like to create a conditional statement based on which way it is being run.  Ex:

If (needed function)
    echo("I'm running in daemon mode");
else echo{"I'm running in console mode");

I'm looking for the needed function to accomplish this from within the script.  thank you.
0
jaym25
Asked:
jaym25
  • 4
  • 3
1 Solution
 
gr8gonzoConsultantCommented:
0
 
jaym25Author Commented:
getopt() appears to be a very powerful function with unlimited options.  Would you happen to have an example with the correct parameters or options?
0
 
gr8gonzoConsultantCommented:
$options = getopt ("d");
$daemon_mode = isset ($options ["d"]);

So if you run your script with a -d parameter, $daemon_mode will be true. Otherwise it will be fails.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gr8gonzoConsultantCommented:
Sorry. My phone auto corrected incorrectly.  

"...will be false."
0
 
jaym25Author Commented:
I thought that was it.  but when I try this code it always shows as false...  
The command I use to enter daemon mode is:  
PID=`$DAEMON > /dev/null 2>&1 & echo $!`  
Perhaps I could add a parameter to this command line?
0
 
jaym25Author Commented:
where $DAEMON is the path to the script
0
 
gr8gonzoConsultantCommented:
PID=`$DAEMON -d > /dev/null 2>&1 & echo $!`
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now