0

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

1 Answer 1

2

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"

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the feedback i thought so. What would be the right syntax?
take a look at this answer stackoverflow.com/questions/3848901/…
if I use php cgi than it works php-cgi -f /media/linkstation/myfolder/import/import.php id=4 but would be possible to create a cronjob for this?
thats a separate problem/solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.