user962449
user962449

Reputation: 3873

how do you run a php file from ssh?

I'm using from ssh:

php filename.php

and works great, but when I do this:

php filename.php?id=2

I get a "could not open input file" error.

any ideas?

Upvotes: 7

Views: 3423

Answers (4)

SSH This
SSH This

Reputation: 1929

You need to pass your parameters as arguments instead and use $argv:

<?php
var_dump($argv);
?>

http://php.net/manual/en/reserved.variables.argv.php

Upvotes: 1

m4t1t0
m4t1t0

Reputation: 5721

You can't pass GET variables via the command line!! If you need to pass a variable to your script you can use php filename.php your_variable and use $argv and $argc in your PHP code.

Upvotes: 9

Andy Lester
Andy Lester

Reputation: 93636

The filename.php?id=2 syntax is only for web servers.

What you did was tell the shell to find a file named filename.php?id=2 and pass it to PHP, but that file doesn't exist.

Upvotes: 1

Cobra_Fast
Cobra_Fast

Reputation: 16061

PHP file's that were written as a website will only be of limited use on CLI.

You could write a wrapper script, that prepares the superglobals and include's the webscript.

I recommend reading about the CLI interface to understand what it does.

Upvotes: 1

Related Questions