tags:

views:

86

answers:

1

I have a PHP script that makes a few calculations and SQLite3 queries/transactions using PDO. Its both hosted and tested on my laptop running a windows/nginx/fastcgi php5.2 server.

I ran it both in the console and in the browser, and to my surprise, the console version took 78 seconds while it took firefox only 55 seconds to finish.

Since this was done using only twenty datasets, and the full dataset is over 1000, I'd like to figure out why the console version is slower and whether I can speed it up to the browser's speed, since I'd like to run the script as a batch file daily without having it launch a browser each time.

P.S. I already did all the optimization I could find with regards to the SQL code (using prepared statements, putting it all in a single transaction)

Any input is appreciated.

+1  A: 

PHP doesn't run in browsers. PHP is server-side technology which feeds it's output to the browser. A more proper question would be phrased as comparing the Command line interface to the server embedded interface (mod_php, or cgi). My guess is the the CLI has to load the PHP code on start-up, so will be slower for short scripts where this load time is significant vs. the web server where the PHP code is already loaded (in the case of mod_php) and ready to process a script.

Devin Ceartas
Sorry if I didn't word it properly. But I don't think your explanation is correct. I tried running a simple "hello world" php script on the command line and it took a fraction of a second. So the time it takes to load the PHP code in the command line should be negligible in both cases.