Linux system uses the command line to execute the php file transfer step

  

Linux users often encounter php files. In the face of these php files, we sometimes use the command line to execute php files for parameter transfer. But how do you do this? Today, Xiaobian will explain to you how to execute php files through the command line in the Linux system.

specific steps:

do multilingual search index, but php program to be executed by the file system of Linux command in php, php files so the variables can not be Obtain.

So to pass the parameters, but the command line to execute php, is not going to Apache and other such things, there is no http protocol, all get, post pass parameters do not work at all, and will be reported, As follows:

root@test:/pub/www/# php /pub/www/product/Crondo/makeindex.php? Lang=en

Could not open input file: /pub/www/product/Crondo/makeindex.php? Lang=en

You can get the parameters to be passed by getting the system environment variable $argv in the php executable file

1.test.php test file:

#! /usr/bin/php

"? Php

print_r($argv);

echo “\ ”;

echo “Total number of paramter is : “.$argc;

echo “\ ”;

?

2. Command line call:

test@ubuntu:~/php$ php test.php 111 222 333 444

All param is :

Array

(

[0] =》 test.php //Parameter 0, file name of the script itself

[1] =》 111//parameter 1< Br>

[2] =》 222//parameter 2

[3] =》 333//parameter 3

[4] =" 444//parameter 4

)

Total number of paramter is : 5 //$argc is the total number of arguments

This way of passing arguments is very similar to the shell

test @ubuntu:~/shell$ sh test.sh 111 222

Two parameters 111,222 are passed to test.sh, the shell will get three parameters, $0 for the file itself, $1 for parameter 1, $2 For the parameter 2. The difference is that php gets in the form of an array, and the shell is not

The above is the method of using the command line to execute the php file in the Linux system, and it will not be used. Let's take a look at it, I believe that after reading this tutorial, it will make you more comfortable with this operation. Solution.

Copyright © Windows knowledge All Rights Reserved