PHP 和cli 有什麼關係 ,運行一個PHP檔案 報錯,該如何解決

來源:互聯網
上載者:User
PHP 和cli 有什麼關係 ,運行一個PHP檔案 報錯
這是報錯資訊 This example script is written to run under the command line ('cli') version of the PHP interpreter, but you're using the 'apache2handler' version


下面是我啟動並執行php 檔案 內容
if (php_sapi_name() != "cli") { //應該是這句話 是不是要配置某個選項 支援 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);
}
?>

------解決方案--------------------
command-line interface 命令列介面
用命令列工具運行它 linux命令列,或win的cmd都可以
------解決方案--------------------
類似於shell吧..就是命令列工具了,環境變量什麼的當然就不一樣了。如果你的腳本是web的那就不要在cli下調試,否則多數可能都會出錯。其他的不是很瞭解,cli基本沒有這麼在下面跑過東西
------解決方案--------------------
意思是說,你的這段代碼是設計運行在CLI模式下的,但是你現在用的是apache web伺服器, 所以這段代碼不能運行.
CLI 是命令列模式,例如在winXP 的命令列視窗cmd 裡邊,php my_script.php 使用php.exe 直接運行php代碼,相當於控制台應用。
不是web伺服器上啟動並執行。
真需要的話,改成 web伺服器上啟動並執行版本就可以。$argv[0] 是從命令列擷取的參數,改成用變數設定或$_GET或$_POST 獲得
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.