Solved

PHP script determine if running a daemon or console

Posted on 2014-09-22
7
288 Views
Last Modified: 2014-09-23
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
Comment
Question by:jaym25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40338302
0
 

Author Comment

by:jaym25
ID: 40338324
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
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 40338363
$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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40338364
Sorry. My phone auto corrected incorrectly.  

"...will be false."
0
 

Author Comment

by:jaym25
ID: 40338400
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
 

Author Comment

by:jaym25
ID: 40338403
where $DAEMON is the path to the script
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40339257
PID=`$DAEMON -d > /dev/null 2>&1 & echo $!`
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
e commerce steps shown instead of self testing 2 59
history of pages 7 55
Joomla Editing 3 23
Can't Find The Code 15 22
This article discusses four methods for overlaying images in a container on a web page
Fine Tune your automatic Updates for Ubuntu / Debian
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question