Sam
Sam

Reputation: 1229

Run php script from URL in command line

Can I run a php script from command line with the following usage:

php http://phpfile.php username password config_file

When I run this it says cannot open input file http://phpfile.php

If there is what would be the best way to execute this within a php script?

Thanks

Upvotes: 0

Views: 3892

Answers (1)

Yash Kumar Verma
Yash Kumar Verma

Reputation: 9630

This is practically not possible. You cannot execute a php script hosted on someone else's server in your cli.

WHY?

Consider this case. Facebook has a php script which adds a comment to the database. So What would be the outcome if someone executes this script from local command line, and goes about adding comments to the database ? This would really mess up the systems. Or consider something like a file hosting script. You can very well imagine the outcomes if anyone can delete any file from their own cli.

Solution!

The file can be executed if:

  • Either you have the script saved locally and run it
  • Or make a get or post request to script with required data and make it do stuff.

Summing up

You can execute it only if the owner allows it (via get and post requests)

Refer these

Do a post request using Guide to making requests

Upvotes: 2

Related Questions