What is the relationship between PHP and CLI, running a PHP file error, how to resolve
Source: Internet
Author: User
What does PHP have to do with the CLI, running a PHP file with an error
Here is the error message This example script was written to run under the command line (' CLI ') version of the PHP interpreter, but you ' re usi ng the ' Apache2handler ' version
Here is the contents of the PHP file I am running
if (Php_sapi_name ()! = "CLI") {//should be this sentence is not to configure an option to support the CLI AH
Print "This example script was 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);
}
try {
Open the database for update, creating a new database if necessary.
$database = new Xapianwritabledatabase ($argv [1], Xapian::D b_create_or_open);
$indexer = new Xapiantermgenerator ();
$stemmer = new Xapianstem ("中文版");
$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);
Set the database handle to Null to ensure that it gets closed
Down cleanly or uncommitted changes is lost.
$database = Null;
} catch (Exception $e) {
Print $e->getmessage (). "\ n";
Exit (1);
}
?>
------Solution--------------------
Command-Line interface Command line interface
Run it with a command-line tool, or win CMD can be a Linux command line
------Solution--------------------
Like the shell. is the command-line tool, the environment changes what is certainly different. If your foot is a web, do not try to do it under the CLI, or the number of numbers may be wrong. The other is not very understanding, the CLI basically did not run under the east
------Solution--------------------
It means that your code is designed to run in CLI mode, but you're using an Apache Web server, so this code doesn't work.
CLI is a command-line mode, for example, in WinXP command-line window cmd inside, PHP my_script.php uses Php.exe to run PHP code directly, equivalent to console application.
is not running on a Web server.
If you really need it, change it to a version that runs on the Web server. $ARGV [0] is a parameter obtained from the command line, changed to be obtained with variable settings or $_get or $_post
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.