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.
jaym25Asked:
Who is Participating?
 
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
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.