This article solves the problem that the php script for task planning in php cli mode is always unsuccessful and reports "require loading path error". after some research, to find the problem. here we will share it with you. Today, my colleague suddenly told me that the execution of a php script I wrote for a scheduled task is always unsuccessful.
The script itself is very simple. it contains only a few library files and executes a function. the function should be correct and called elsewhere. I access the page locally using a browser and the execution is successful. it seems that there is no problem. I suspect it is a problem with my colleagues' scheduled tasks. I opened the command line again and used php to directly execute the script. this time, an error is reported. it is a file error in require. it seems that the path is incorrect.
I don't know why, but the error is that the path is incorrect. I guess it is related to the relative path. so I changed all the relative paths to the absolute path, and then executed the task to solve the problem.
After searching on Baidu, when the script is executed using php, the script is executed in the path of the current php command, so the relative path is incorrect. There are two solutions to the problem:
I. changing to an absolute path is troublesome. an error may occur if any of the contained files includes the file paths included in the directly contained files, therefore, it is only available when the execution file is relatively simple.
2. use the chdir function to change the current execution directory and change the directory to the directory where the FILE is located. chdir (dirname (_ FILE __));
Finally, let's briefly introduce the cli mode of PHP.
First, go to the CLI (Command line interface) mode of PHP.
Cyguin-> $./php -- ini (display configuration file information)
Will display:
configuration file(php.ini) path: c:/WindowsLoaded configuration file: c:/wamp/bin/php/php5.3.0/php.iniscan for additional .ini files in: (none)additional .ini files parsed: (none)
$./Php -- help (PHP details are displayed)
$./Php -- rf (Display Function information)
$./Php -- fc (Display Class information)
$./Php -- re (Display Extended information)
$./Php -- ri (Display Extended configuration)
$./Php-l : Check syntax
For example: $./php-l c:/wamp/www/1.php
Running result: No Syntax errors detected in xxx
$./Php-v: Display version information and running mode cgi/cli
Running result:
PHP 5.3.0 (cli) (built: Jun 29 2009 21:25:23)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
$./Php-f : Parse and execute files
For example: $./php-f c:/wamp/www/1.php
$./Php-h: Display help files
$./Php-r: Run PHP code, no need to use <? Php?> Tag
For example: $./php-r'print ("hello! "); 'Or $./php-r'echo" hello! ";'
Running result: hello!
$./Php-: Enter the interaction mode
In linux, the following occurs:
Php>
In windows:
Enter:
<?phpecho "hello world!";?>
Then ctl + c is used to obtain the output.
In PHP5.3.0, this cannot be used directly because the results cannot be obtained directly.
<?phpecho "hello world!";?>
Enter ctl + z and then ctl + c. The result is displayed.
$./Php-c: Specifies the location for finding php. ini or a specific ini file.
$./Php-n: Do not use php. ini
$./Php-d foo [= bar]: Define that the value of foo entry in the INI file is bar.
$./Php-m: Displays all modules, including php modules and zend modules.
$./php -e : Generate extended information for debugger/profiler
$./Php-B : Process the code executed by the standard input tab. PHP5 is newly added.
For example:
$./Php-B 'echo "hello world ";'
Output result: hello world
$./Php-R : Php code executed for each row. PHP5 is newly added.
$./php -F :
$./Php-H : Code executed after processing input
$./Php-s: Display HTML syntax highlighted code
$./Php-w: Get the code after removing spaces and comments
For example:
$./Php-w c:/www/1.php
$./Php-z : Load Zend extension files
$ Pwd: displays the current path
--enable-cli, --enable-cgi