fefe
fefe

Reputation: 9055

execute php via cli passing arguments

how do I execute via command line a php script passing get paramateres. I have been trying to execute the following

chmod +x /media/linkstation/myfolder/import/import.php

sudo php5 ./media/linkstation/myfolder/import/import.php?id=4

but won't work Could not open input file

Upvotes: 0

Views: 2056

Answers (1)

Flosculus
Flosculus

Reputation: 6946

You are trying to mix file protocol with http protocol, that won't work.

The parameters need to be separated from the file path.

Edit:

As long as the path is correct, you can try:

sudo php5 ./media/linkstation/myfolder/import/import.php id=4

Now the first arg $argv[1] is the query string, so long as that is a single string (or wrapped in quotations) it will appear on the receiving end of the script. After that you can treat it as you like.

However there are more suitable ways to delivery parameters. You may find command line options more useful: http://php.net/manual/en/function.getopt.php

sudo php5 ./media/linkstation/myfolder/import/import.php --id="4"

Upvotes: 2

Related Questions