Page 1 of 1
Web to cli in self script?
Posted: Mon Nov 15, 2010 4:38 am
by scuar
Hello, is it possible to make a web script to self execute itself in CLI mode?
My script has something like this:
Code: Select all
if(isset($_SERVER['argc']) && ($_SERVER['argc'] >= 1))
{
//do something
}
else
{
if(//nothing set)
{
print 'html source + option to execute the script in cli';
}
}
And to execute itself i use:
Code: Select all
function execCli()
{
shell_exec("php " . __FILE__ );
}
But nothing happens, so i was wandering after all if it's possible to do this.
Thanks.
Re: Web to cli in self script?
Posted: Mon Nov 15, 2010 12:02 pm
by Christopher
scuar wrote:Hello, is it possible to make a web script to self execute itself in CLI mode?
Yes.
scuar wrote:But nothing happens
How do you know that the script does not run?
Re: Web to cli in self script?
Posted: Mon Nov 15, 2010 12:32 pm
by Eric!
Also, some servers are configured to prevent shell executions. What you posted appears like it should work provided the path to the php CLI is in your environment variables (otherwise specify a path and some switches
so either
shell_exec("php -f" . __FILE__ );
or
shell_exec("/path/to/bin/on/your/system/php -f" . __FILE__ );
Start small with something like
Code: Select all
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
http://php.net/manual/en/function.shell-exec.php
http://www.php.net/manual/en/features.c ... ptions.php
Furthermore you might try exec() and see where it is running from. If it is in safe mode then it will only run things inside the safe mode directory.
http://www.php.net/manual/en/ini.sect.s ... e-exec-dir
Re: Web to cli in self script?
Posted: Wed Nov 17, 2010 5:02 am
by scuar
How do you know that the script does not run?
I know it because it should create a new file but it doesn't.
Furthermore you might try exec() and see where it is running from. If it is in safe mode then it will only run things inside the safe mode directory.
Great, i'll try.
Thank you both, i bet it's just a coding mistake.