php框架workerman偽靜態改造詳細說明

2022-03-25 00:28:51 字數 1048 閱讀 8266

一、找到\vendor\workerman\workerman\webserver.php 第176行,改為以下內容,增加對html副檔名檔案不存在的判斷:

if (in_array($workerman_file_extension,['php','html']) && !is_file($workerman_file

)) /index.php";

$workerman_file_extension = 'php';

if (!is_file($workerman_file

)) /index.html";

$workerman_file_extension = 'html';

}}

這樣以後,只要訪問擴充套件名為html的檔案,且這個檔案不存在,就會自動重定向到index.php,然後再在index.php進行判斷就行

二、index.php改造,輸出頁面前,增加以下判斷:

1

//重定向判斷

2$uri=$_server['request_uri'];

3$ext=strtolower(substr($uri,-4,4));

4if(is_cli()&&$ext=='html')

我訪問的位址是即訪問index.php?_=users_login

三、根據$_get['_'],分割下劃線,判斷載入哪乙個類和類的方法,就行了。比如:

1

$_get['_']=isset($_get['_'])?$_get['_']:strcode('index_index');

2$strs=strcode($_get['_'],'decode');

3if(!$strs)xdie('param error.');

4$d=preg_split('/[\.\_]/',$strs);5

if(count($d)<2)xdie('error:param');

6$class=$d[0].'action';

7$action=$d[1];

再載入類並執行就行

workerman框架的安裝 mac版安裝

mac os 自帶php,但是可能缺少pcntl擴充套件,這就需要安裝pcntl擴充套件 執行php m 檢視會列出命令列 php cli 已經安裝的擴充套件,結果類似如下 php m php modules libevent posix pcntl php ini configuration fi...

workerman怎樣統計框架裡的函式執行情況

不同的框架,略有不同。首先,在index.php檔案中,需要加入。載入vendor,統計服務 rpc client等.require dir vendor bootstrap autoloader.php bootstrap autoloader instance addroot dir init ...

workerman定時器使用 php定時任務

add int workerman lib timer add float time interval,callable callback args array bool persistent true 定時執行某個函式或者類方法 引數time interval 多長時間執行一次,單位秒,支援小數,...