简体   繁体   中英

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM