The command line executes the php script with parameters and obtains the parameters
Published on 2011-07-15
Category: php
First, why do we run the php script under the command line?
Personally understood, there are two main reasons:
1. Using crontab to run PHP can decompress the server. Of course, there is a condition here, that is, the real-time requirements are not high. For example: the real-time requirements for friend updates in SNS are not high, but the amount of data is relatively large. If run regularly at this time, it will put a lot of pressure on the web server and database server.
2. We need to complete a certain thing regularly. For example: I want to delete a user's message a month ago. At this time, the written php script is executed in crontab. It only needs to be run once a day. Instead of manually executing the php program.
Second, execute php with parameters under the command line and obtain the parameters
One thing is very important, that is, executing php under the command line, does not use apache and other such things, there is no http protocol, all get and post are transmitted The parameters have no effect at all, and an error will be reported, as follows:
zhangying@ubuntu:~$ php test.php?aaa=bbb
Could not open input file: test.php?aaa=bbb
General In some cases, there is no need to pass parameters to the scheduled php script, but sometimes, it is necessary.
1, test.php test file, very simple, right?
View copy and print?