Cleankod
Cleankod

Reputation: 2340

PHP CLI - which command should I use?

I have one server (test) which has "php" command that I can run CLI with. The other server (hosting) runs only with "php5-cli" command.

Example:

exec("php file.php"); // Works on test server
exec("php5-cli file.php"); // Works on hosting server

How can my script detect which one to use?

Upvotes: 2

Views: 570

Answers (5)

the JinX
the JinX

Reputation: 1980

Why not make a symlink to the executable on one of the servers ln -s so that one of them is available on both servers.

That should solve this problem.

Upvotes: 1

xzyfer
xzyfer

Reputation: 14135

Could you symlink php-cli as php or vise versa?

That way either would work.

Upvotes: 1

powtac
powtac

Reputation: 41080

Make sure which php.ini is included when using each of them.

Upvotes: 1

Matthew
Matthew

Reputation: 48314

php-config --php-binary
php-config5 --php-binary

But you probably run into similar problems of no guarantee what that command is called (or that it exists). Not sure how many hosting companies use it.

Upvotes: 1

Quamis
Quamis

Reputation: 11087

Make a config value specific to each server. On some servers you will encounter php5 as a cli command, instead of php:) And the system administrator may easily rename or symlink the executable to any name he likes.


edit: try something along the lines of :

$output = Array();
$result = -1;
exec("php -f myScript.php", $output, $result);
if($result==-1){
    // you should try to exec use the other method here
    echo "app 'php' not found";
}else{
    // the exec was a success
}

Upvotes: 1

Related Questions