Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run PHP script from shell or apache server

I am wondering if a PHP script can be executed from a shell command line.

Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.

Is it better to run a script from shell for performance and also is it better to run it from windows or unix/linux

I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.

Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows? all I have at the moment installed is WAMP, which has mysql, php and apache server.

I am sorry for being a novice.

thanks for your kind help

like image 606
David Garcia Avatar asked Jul 17 '26 14:07

David Garcia


1 Answers

I am wondering if a PHP script can be executed from a shell command line.

Yes

Does a script executed from shell have the exact functionality if executed from the browser? or is there a difference in coding.

It won't have $_REQUEST and friends populated, and $_SERVER won't have server information in it.

Is it better to run a script from shell for performance

Maybe. It avoids the overhead of runnning a webserver. It stops you having cached versions in memory for faster re-execution.

and also is it better to run it from windows or unix/linux

Benchmark it.

I am asking all these questions because, I am suppose to develop a PHP script that can fetch some data from http headers of some urls listed in a MySQL db and then store the data in the database.

There doesn't seem to be any need to involve a web server for that.

Can you guys point me to the right direction please, Do I need ubuntu, or is there a shell that can run php from windows?

The standard Windows shell can.

all I have at the moment installed is WAMP, which has mysql, php and apache server.

You'll need the command line version of PHP. I've no idea if WAMP includes it or not.

like image 108
Quentin Avatar answered Jul 21 '26 06:07

Quentin