If you are looking for software to use, go to Huajun Software Park! software release AI product list
Location: Home pageTutorial strategyTutorialComputer software tutorials Linux system...

Steps to use command line to execute php file parameter transfer in Linux system

Author: Itachi Uchiha Date: 2017-05-19

Ubuntu For Linux
Ubuntu For Linux-14.10

operating system Storage size: 1158720KB Time: 2014-04-22

Software Introduction: Ubuntu is a freely distributed and open source Linux-based operating system designed for humans, humans who have no previous experience with Linux...

Download now

Linux users often encounter php files. Faced with these php files, we sometimes use the command line to execute the php file to pass parameters. Today, the editor of Huajun will show you the steps to use the command line to execute PHP file parameter transfer in Linux system. I hope you can support and share the carefully selected content. If you like it, hurry up and get it! .

52-150521112320436.jpg

Specific steps:

To do a multi-language search index, the PHP program must execute the file through the PHP command in the Linux system, so the variables in the PHP program file cannot be obtained.

Therefore, parameters must be passed, but when executing PHP from the command line, Apache and other such things are not used. There is no http protocol. All get and post parameters will not work at all, and an error 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 execution file

1.test.php test file:

#! /usr/bin/php

"? php

print_r($argv);

echo "n";

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

echo "n";

? 》

2. Command line call:

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

All param is:

Array

(

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

[1] =》 111//Parameter 1

[2] =》222//Parameter 2

[3] =》333//Parameter 3

[4] =》444//Parameter 4

)

Total number of paramter is: 5 //The value of $argc is the total number of parameters

This method of passing parameters is very similar to shell

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

Two parameters 111 and 222 are passed to test.sh, and the 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 it in the form of an array, but the shell does not.

The above is the editor's summary of how to use the command line to execute PHP files to transfer parameters in Linux systems. Users who are not familiar with this operation should come and take a look. I believe that after reading this tutorial, you will have a better understanding of this operation.

Related articles