Php-cli

bkessell

Verified User
Joined
Sep 4, 2006
Messages
5
I know that when you run a php file from the CLI that you must have a line similar to the following at the beginning. What is the line for your servers?

#!/usr/local/lib/php -q
 
When I run the file from a browser, it only spits out "#!/usr/local/bin/php -q" without the quotes and doesn't run the script.
 
you are running the script in a browser othen than CLI?

but in your first post you stated "run a php file from the CLI"

i am confusing :confused:


anyway you dont need the she-bangs line unless you are writing CGI PHP or PHP shell script.
 
Well, I thought that if i just ran it through the browser to test it, that it would turn out the same way. I've never ran a script from the CLI before. Its only a database backup program that uses mysqldump and the php date() function to assign the new file name. Here is what I would like to run from the CLI by using a cron job:

#!/usr/local/bin/php -q
<?php

$filename = './backup/' . date('D-M-j-o') . $database . '.sql';
echo shell_exec ('mysqldump.exe --add-drop-table -u user -ppassword database > ' . $filename);
?>


When the script is run through Cron, I get the following error in an email:

Usage: php [options] [-f] <file> [args...]
php [options] -r <code> [args...]
php [options] [-- args...]
-a Run interactively
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f <file> Parse <file>.
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-r <code> Run PHP <code> without using script tags <?..?>
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.

args... Arguments passed to script. Use -- args when first argument
starts with - or script is read from stdin
 
Last edited:
hehachris said:
anyway you dont need the she-bangs line unless you are writing CGI PHP or PHP shell script.

you have two choices if you want to run it as cron (=CLI):


1, Leave the she-bangs line, chmod the script to 755 or excecutable by the user who runs the cron.
and create a cron like this:
* * * * * /path/to/script.php


2, Delete the she-bangs line, and create a cron like:
* * * * * /usr/local/bin/php /path/to/script.php
 
Hi,

in some stupid attempt to install php without having to recompile I apt-get installed it from dotdeb...

I solved it serverside by doing a ./build php_ap2 BUT... php-cli is still a dotdeb compile.

This wouldn't be a problem if mysql wasn't buildin the wrong way.

Is there any way to recompile da's php cli?
 
Solution to my problem was easy.

DA compiles the cli version to /usr/local/bin/php while the DEB's install to /usr/bin/php.

Removing the compiled php packages solved the problem because the system is look in /usr/bin/ first before checking in /usr/local/bin/php.

apt-get remove php4-cli
apt-get remove php5-cli

solved everything.
 
Last edited:
Back
Top