How to execute a php script with parameters and obtain parameters based on command lines

Source: Internet
Author: User
This article mainly introduces how to execute a php script with parameters based on the command line and obtain parameters. it analyzes the principles, usage, and precautions of running PHP code using the command line, for more information about how to execute a php script with parameters based on command lines and obtain parameters, see this document. We will share this with you for your reference. The details are as follows:

1. why should we run the php script on the command line?

For personal understanding, there are two main reasons:

1. using crontab to run php can decompress the server. of course, there is a condition that the real-time requirement is not high. For example, the real-time requirement for friend dynamics in sns is not high, but the data volume is large. if you run regularly at this time, the web server and database server will share a lot of pressure.

2. that is, we need to regularly complete a task. for example, I want to delete a message from the user a month ago. at this time, the php script written is executed on crontab, you just need to run it once a day. Instead of executing the php program manually.

2. execute php with the parameter in the command line and obtain the parameter

One thing is very important,The code is as follows:

Zhangying @ ubuntu :~ $ Sh c1.sh aaa bbb


I passed two aaa bbb parameters to c1.sh, and shell will get three parameters. $0 is the file itself, $1 is parameter 1, and $2 is parameter 2. The difference is that php gets an array instead of a shell.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.