Page 1 of 1
Script for a web server and CLI
Posted: Wed Nov 03, 2010 10:43 pm
by scuar
Hello,
i was wondering if is it possible to make a script that is able to be executed from a webserver and from a CLI aswell.
I'm not shure how to check if variables are passed trough an url or by command line.
I've heard that execution time from CLI to regular php execution, is it true?
Scuar.
Re: Script for a web server and CLI
Posted: Wed Nov 03, 2010 11:08 pm
by s.dot
Yes, it is possible.
Although, the CLI php.ini settings file may differ from the web server php.ini settings file.
I'm not sure if this is needed, but in your script, you can check if running from the browser or command line by doing this:
Code: Select all
$cli = isset($_SERVER['argc']) && ($_SERVER['argc'] >= 1);
if ($cli)
{
//command line
} else
{
//browser
}
Re: Script for a web server and CLI
Posted: Wed Nov 03, 2010 11:51 pm
by scuar
Delete this post please
Re: Script for a web server and CLI
Posted: Fri Nov 05, 2010 9:23 am
by scuar
Great!, it was so simple.
Thanks a lot.
EDIT:
Oops i didn't realize i misspell this question "I've heard that execution time from CLI to regular php execution, is it true?"
What i need to know it's if a cli script can be executed for hours or days (i'm plaining on using sleep() and each hour do something) and if a web script can do it as well.