What is the relationship between PHP and cli? how can I solve an error when running a PHP file?

Source: Internet
Author: User
What is the relationship between PHP and cli? run a PHP file to report an error. this is the error message Thisexamplescriptiswrittentorununderthecommandline ('cli ') versionofthePHPinterpreter, butyou 'reu PHP and cli. run a PHP file to report an error
This is the error message: This example script is written to run under the command line ('cly') version of the PHP interpreter, but you're using the 'apache2handler' version


Below is the content of the php file I am running
If (php_sapi_name ()! = "Cli") {// is it necessary to configure an option to support cli?
Print "This example script is written to run under the command line ('cli ') version of \ n ";
Print "the PHP interpreter, but you're using the '". php_sapi_name (). "'version \ n ";
Exit (1 );
}

Include "xapian. php ";

If ($ argc! = 2 ){
Print "Usage: {$ argv [0]} PATH_TO_DATABASE \ n ";
Exit (1 );
}

Try {
// Open the database for update, creating a new database if necessary.
$ Database = new XapianWritableDatabase ($ argv [1], Xapian: DB_CREATE_OR_OPEN );

$ Indexer = new XapianTermGenerator ();
$ Stemmer = new XapianStem ("english ");
$ Indexer-> set_stemmer ($ stemmer );

$ Para = '';
$ Lines = file ("php: // stdin ");
Foreach ($ lines as $ line ){
$ Line = rtrim ($ line );
If ($ line = "" & $ para! = ""){
// We 've reached the end of a paragraph, so index it.
$ Doc = new XapianDocument ();
$ Doc-> set_data ($ para );

$ Indexer-> set_document ($ doc );
$ Indexer-> index_text ($ para );

// Add the document to the database.
$ Database-> add_document ($ doc );

$ Para = "";
} Else {
If ($ para! = ""){
$ Para. = "";
}
$ Para. = $ line;
}
}

// Set the database handle to Null to ensure that it gets closed
// Down cleanly or uncommitted changes may be lost.
$ Database = Null;
} Catch (Exception $ e ){
Print $ e-> getMessage (). "\ n ";
Exit (1 );
}
?>

------ Solution --------------------
Command-line interface command line interface
You can use the command line tool to run linux command lines, or win's cmd command lines.
------ Solution --------------------
It is similar to shell. it is a command line tool, and the volume of environment changes is not the same. If your website is web, do not configure hosts in cli. otherwise, multiple hosts may be generated. Others are not very familiar. cli basically does not run things below
------ Solution --------------------
This code is designed to run in CLI mode, but you are currently using an apache web server, so this code cannot run.
CLI is the command line mode. for example, in the command line window cmd of winXP, php my_script.php uses php.exe to directly run php code, which is equivalent to a console application.
It is not running on the web server.
If necessary, you can change it to the version running on the web server. $ Argv [0] is a parameter obtained from the command line. it is obtained by using variable settings or $ _ GET or $ _ POST.

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.