2024年4月12日发(作者:)

PHP命令行运行模式(PHP command line run mode)

The method and technique of running PHP under command line

Submitted by rocing on 2008, December 12, 9:57 AM. PHP learning

In Linux, execute the PHP file directly with the "PHP" command

The code that runs PHP files normally under the Linux command

line:

XML/HTML code

Execute under : #php installation path, -f PHP file

path

2 example: /opt/modules/php/bin/php, -f,

/opt/data/www/yoururl/

Each input PHP installation path is more troublesome, in fact,

we can not input oh!

Copy the file /opt/modules/php/bin/php to /usr/sbin, and PHP

will be installed as the Linux command

Under Linux, execute the following command

XML/HTML code

/opt/modules/php/bin/php /usr/sbin

This can be used directly on the command line

XML/HTML code

-f /opt/data/www/yoururl/

Execute the PHP program and omit the input path

PHP receive parameter in command line

In the command line, the input parameter to the PHP file is

different from that under the HTTP protocol. It is not received

by variable name, but rather by location in the first few

The first parameter is received by $_SERVER['argv'][1], and the

second parameter is received by $_SERVER['argv'][2]

This is written in /opt/data/www/yoururl/:

XML/HTML code

01.

(isset ($_SERVER['argv'][1])) {

03.$year = $_SERVER['argv'][1];

04.} else {

05.$year ='null';

06.}