PHP command Line (CLI) mode report require load path error resolution _php tips

Source: Internet
Author: User
Tags php script zend

Today, my colleague suddenly told me that the execution of a PHP script I wrote was always unsuccessful.

The script itself is simple, it contains only a few library files and executes a function, the function should have no errors, this function has been called elsewhere, no problem. I have a local browser to access the page, the success of the implementation, it seems that there is no problem, I am a little skeptical of the work of colleagues to plan the problem. I also opened the command line, using PHP to execute the script directly, this return is wrong, is require contains file errors, it seems that the path is wrong.

Do not understand what causes, just from the error point of view is the wrong path, I guess is related to the relative path, so the relative path of all to the absolute path, then implementation, problem solving.

After Baidu search, know that the script is executed in PHP, the location of the execution script is currently executing the PHP command path, so the relative path is wrong. There are two ways to solve the problem:

One, instead of absolute path, this is more troublesome, all the included files include files included in the file path, there is a wrong can be wrong, so only when the execution of the file is simpler when available.

Second, the use of the ChDir function, change the current execution directory, the directory to the file directory, ChDir (dirname (__file__));

Finally, briefly introduce the CLI command line mode of PHP.

First, go to PHP's CLI (Command line interface) mode

Cyguin-> $./php--ini (Display profile information)

will display:

Configuration file (php.ini) path:c:/windows
Loaded configuration File:c:/wamp/bin/php/php5.3.0/php.ini
Scan for additional. ini files in: (none)
additional. ini files parsed: (none)

$./php--help (PHP specific information will be displayed)
$./php--rf <name> (display <name> function information)
$./php--FC <name> (Show <name> class information)
$./php--re <name> (show <name> extended information)
$./php--ri <name> (show <name> extended configuration)

$./php-l <file> : Checking grammar
such as: $./php-l c:/wamp/www/1.php
Run Result: No Syntax errors detected in XXX

$./php-v : Display version information and run mode CGI/CLI
Run 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 <file>: parsing and executing files
such as: $./php-f c:/wamp/www/1.php

$./php-h : Displaying Help files

$./php-r <code> : Run PHP code without the need to use <?php?> tags
such as: $./php-r ' Print ("hello!"); ' or $./php-r ' echo ' hello! ';
Run Result: hello!

$./php-a : Entering interactive mode
It will appear under Linux:
php>
Under Windows:
Need to enter:

<?php
echo "Hello world!";
? >


Then ctl+c to get the output.
In PHP5.3.0, it cannot be used directly, because the result cannot be obtained directly.

<?php
echo "Hello world!";
? >

Enter the Ctl+z first, then enter the Ctl+c, and you will get the result.

$./php-c : Specifies the location of the lookup php.ini, or specifies a specific INI file.

$./php-n : Do not use php.ini

$./php-d foo [=bar] : The value of foo entry in the definition INI file is bar

$./php-m : Show all modules, PHP modules and Zend Modules

$./php-e : Generate extended information for Debugger/profiler

$./php-b <begin_code> : code to handle standard input check execution. PHP5 new addition.
Such as:
$./php-b ' echo ' Hello World ';
Output Result: Hello World

$./php-r <code> : PHP code executed for each line. PHP5 new addition.

$./php-f <file> :

$./php-h <end_code> : code executed after finishing the input

$./php-s : code to display HTML syntax highlighting

$./php-w : Get rid of spaces and comments after the code
Such as:
$./php-w c:/www/1.php

$./php-z <file> : loading Zend Extension Files

$PWD: Show Current path

--ENABLE-CLI,--enable-cgi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.