Execute php file from command line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GeXus
Forum Regular
Posts: 631
Joined: Sat Mar 11, 2006 8:59 am

Execute php file from command line

Post by GeXus »

I have a script, basically a spider.. that I would like to run on the server.. how would I execute it from the command line?

Thanks!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Find php.exe. I believe you use the -r argument to run, but I could be mistaken. I don't run much PHP from the command prompt.

Edit: I'm sorry, I think it's -a.
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Use php from the cli directory, the other php is for fast-cgi.

Usage with php tags in the script:

Code: Select all

php -f "pathtoscript/test.php"
Usage without php tags in the script:

Code: Select all

php -r "pathtoscript/test.php"
For all parameters run:

Code: Select all

php --help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

-r is used for code in the command line, not an external file.
Post Reply