Servers using Linux have built-in PHP environments, so some users will use PHP to write scripts that perform automated tasks, but find that every time you execute a PHP script, you need to use php myscript.php. trouble. In fact, we can directly execute the PHP script file, but how to do it? The following small series will introduce you how to directly execute PHP script files in Unix/Linux.
write your script file
we write a name for test_run.php file here, the contents of the file are as follows:.
Here is some plain text < Br>
Here is the file name:
"? Php
echo $argv[0], PHP_EOL;
? 》
The content of the script is very simple, that is, print the name of the current script file.
Then, we execute this script using PHP commands:
yuanyu@ymac:phpworkspace $ php test_run.php hello
Here is some plain text.
Here is the file name:
test_run.php
yuanyu@ymac:phpworkspace $
Add header information to the script file and set permissions
Then, write the full path of the php command on the first line of this file, in front of a #! :
#! /usr/bin/php
Here is some plain text.
Here is the file name:
"? Php
echo $argv[0], PHP_EOL;
?
Then give this file permission to execute:
yuanyu@ymac:phpworkspace $ chmod u+x . /test_run.php
The script can be executed directly:
yuanyu@ymac:phpworkspace $ . /test_run.php
Here is some plain text.
Here is the file name:
. /test_run.php
yuanyu@ymac:phpworkspace $
This method is also mentioned in the official PHP documentation, please refer to:
http://php. Net/manual/en/features.commandline.usage.php
“Example #2 Script intended to be run from command line (script.php)”
The above is the operation method of directly executing PHP script files in Unix/Linux. Unfamiliar users can refer to the specific steps described above.
jiffies are global variables in Linux systems, which are related to time. What is t
There is no rc.local in SUSE Linux 10, you want to use it you have to write an rc script file in the
Arch Linux is a lightweight Linux system. Learning Arch Linux will give you a bette
In the Linux system, there are a total of 5 commands for finding files, but general
What should I do if VMware does not support full virtualization when installing 64-bit CentOS?
Detailed method for automatic backup and deletion of website data under Linux
Unix uninstall gdb debugging tools trick
Linux forced to delete the U disk virus skills
GDB function summary in Linux system
Parameter Analysis of Linux System xlsfonts Command
How do Linux systems delete icons on the gnome panel?
Win7 system automatic repair function how to start
Countermeasures for deleting folders in Win7
Throwing bricks and jade: Win XP's three alternative operating skills
How to delete the folder "Can't find the item, please confirm the location of the project"?
Cleaning up the six misunderstandings of server virtualization
Analysis of the five advantages of Vista SP2
Lenovo Win10 variant YOGA 4 Pro released: 8499 from
Windows 7 system Windows.old file magic
Win7 system creates a sleep file prompt error code 0xc000007f solution