tp若使用了
define('app_debug',false);
會生成./runtime/~runtime.php 緩存文件,以後每次調用都會用這個文件來處理
但是若一個項目又使用了cli,cli生成的./runtime/~runtime.php 文件跟website是同一個文件,而且cli生成的./runtime/~runtime.php文件少了一些定義,例如__root__
if(!is_cli) { // 当前文件名 if(!defined('_php_file_')) { if(is_cgi) { //cgi/fastcgi模式下 $_temp = explode('.php',$_server['php_self']); define('_php_file_', rtrim(str_replace($_server['http_host'],'',$_temp[0].'.php'),'/')); }else { define('_php_file_', rtrim($_server['script_name'],'/')); } } if(!defined('__root__')) { // 网站url根目录 if( strtoupper(app_name) == strtoupper(basename(dirname(_php_file_))) ) { $_root = dirname(dirname(_php_file_)); }else { $_root = dirname(_php_file_); } define('__root__', (($_root=='/' || $_root=='\\')?'':$_root)); } //支持的url模式 define('url_common', 0); //普通模式 define('url_pathinfo', 1); //pathinfo模式 define('url_rewrite', 2); //rewrite模式 define('url_compat', 3); // 兼容模式}
第一個解決辦法,將is_cli改成0
define('is_cli',php_sapi=='cli'? 1 : 0);
改成
define('is_cli',0);
但是問題並沒有解決,雖然生成了defined('__root__'),但是在cli下生成的
__root__ = .;
而website模式下生成的__root__ = ;
兩者的_php_file_也不同。雖然code相同。
因此這個方案是不行的。
第二個解決辦法,cli和website使用2個不同的runtime cache文件
在入口文件index.php 添加判斷
$is_cli = php_sapi=='cli' ? 1 : 0;if (!app_debug && $is_cli) { define('runtime_file','./runtime/~runtime_cli.php');}
這樣在不同模式下使用各自的runtime文件,不會導致衝突。完美解決! 以上就介绍了tp在app_debug=false的情況下,cli和website會共用同一個~runtimephp導致出錯的問題解決辦法,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。