Detecting CLI/CRON support

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Detecting CLI/CRON support

Post by alex.barylski »

Using strictly PHP is there a reliable method for detecting/updating cron? I want to show a message indicating whether it's enabled or not as my application needs cron functionality.

Also, if cron is not available (shared hosts, etc) I would like to check for the possibility of using CLI to carry out the actions instead. Is there a php.ini setting which I can check that will tell me where and whether or not CLI is possible?

Cheers :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can run the "which" command via system() to find commands (if you're on a *nix based system.)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

I imagine it'll be running mostly on Linux systems...

Although I am not sure I see how I could use this command for my use???

For detecting CLI support? So I would do something like:

Code: Select all

which php5-cli
Which would return the fullpath?

Couldn't i just rely on the error message returned when invoking a command that doesn't exist?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Hockey wrote:Couldn't i just rely on the error message returned when invoking a command that doesn't exist?
Then why did you make this topic in the first place?

There is no way to detect its existence without testing for it or trying to run it. Either way will return some result. Which one are you satisfied with?
Post Reply