A. php開發即時通訊使用的什麼原理
最簡單的說,就是ajax定時刷新,比如間隔10秒。有新數據,就反饋到前台,沒新數據就等待下一次刷新。
但是真正在應用中需要考慮到消息及時性、伺服器壓力等等。
可以用comet進行設計
node.js
、socket
反正當你真的要自己開發一個im系統應用到自己的項目中的話,是一個很大的工程
B. php的工作原理
PHP的所有應用程序都是通過WEB伺服器(如IIS或Apache)和PHP引擎程序解釋執行完成的,工作過程:
(1)當用戶在瀏覽器地址中輸入要訪問的PHP頁面文件名,然後回車就會觸發這個PHP請求,並將請求傳送化支持PHP的WEB伺服器。
(2)WEB伺服器接受這個請求,並根據其後綴進行判斷如果是一個PHP請求,WEB伺服器從硬碟或內存中取出用戶要訪問的PHP應用程序,並將其發送給PHP引擎程序。
(3)PHP引擎程序將會對WEB伺服器傳送過來的文件從頭到尾進行掃描並根據命令從後台讀取,處理數據,並動態地生成相應的HTML頁面。
(4)PHP引擎將生成HTML頁面返回給WEB伺服器。WEB伺服器再將HTML頁面返回給客戶端瀏覽器。
-------------------------------------------------------------------------------------------------------
圖是沒有了
但是簡單就是:
你伺服器開了apache,並且配置好伺服器
有人訪問你的伺服器->訪問了php文件->apeche執行php文件->把結果反饋給用戶
(前提是中間不出錯,出錯返回錯誤信息)
C. 請問這種方式的(index.phpg=System&m=Admin&a=insert)路由控制是什麼php框架寫的
thinkphp有這種模式 g分組 m控制器 a方法
鏈接的意思是告訴框架 我要運行System分組下 Admin.class.php文件中的 public function insert()方法
這種模式其實你自己簡單的寫個路由也可以實現
先get到鏈接中的所有參數 然後將後面的參數轉成數組 按照數組進行調取文件即可
D. 路由器、路由表、路由有什麼區別,聯系
路由器是一個設備, 路由表一路由器里的一組數據 路由是路由器選擇路徑的一個過程 說說他們3者的關系,路由器是用來實現路由功能的設備,(路由功能,意思就是跨網段傳輸數據包,把數據包按照正確的地址發送到目的地的過程,是一個過程,在這個過程中可以選擇最佳路徑),路由器收到數據後,是對照路由表發送數據的,路由表是目標網段和發送網關的對應信息,他的生成是由路由條目學習到的,路由條目又是什麼,就是靜態路由的配置條目,或者動態路由中向相鄰的路由器發送本機路由表的信息,路由表生成後,路由器接到數據包就可以對照路由表把包發送出去 這么說能看明白么?
E. php模板的工作原理是什麼呢求高手指點一二!
方案一:
點擊左邊,
觸發一個js事件,
可能是ajax請求,可能是別的。 (那麼左邊的鏈接,點擊就是一個onclick事件了)
然後js用什麼數據 替換右邊部分的div裡面的內容 (局部替換)
方案二:
該網頁採用iframe框架的結構
F. php 路由作用
建議你了解下restful,所謂的路由就是客戶所訪問的url,只不過url中的一些參數以變數的形式存在。
G. php怎樣不使用框架的情況下本地模擬url路由,實現localhost/a/id/1這種的訪問方式
要實現路由的話你依然需要框架中路由器的支持,因為伺服器不能理解你路徑的具體含義.所以你需要一個路由器來幫助伺服器去處理特定的信息.
不想用現成的就自己寫一個簡單的,如下:
首先你需要在htdoc下放一個.htaccess來實現單文件入口:
<IfMolemod_rewrite.c>
RewriteEngineOn
RewriteRule^$index.php?_url=[QSA,PT,L]
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule^(.*)$index.php?_url=$1[QSA,L]
</IfMole>
然後自己寫路由咯, index.php
<?php
//這里添加你想要的路徑
$route=array(
//(:num)表示匹配任何數字,(:any)表示任意字元
'a/id/(:num)'=>'TestController:idAction',
'a/any/(:any)'=>'TestController:anyAction',
'a/no' =>'TestController:noAction',
//這里是默認控制器,就是當你訪問localhost的時候用
'_DEFAULT_'=>'IndexController:indexAction',
);
//簡單的Router
classRouter
{
private$route;
publicfunction__construct(array$route)
{
$this->route=$route;
}
publicfunctionparse($url)
{
if(empty($url)){
list($controller,$action)=explode(':',$this->route['_DEFAULT_']);
returnarray(
'controller'=>$controller,
'action' =>$action,
'params' =>array(),
);
}
$trans=array(
':any'=>'[^/]+',
':num'=>'[0-9]+'
);
foreach($this->routeas$u=>$d){
$pattern='#^'.strtr($u,$trans).'$#';
if(preg_match($pattern,$url,$params)){
list($controller,$action)=explode(':',$d);
array_shift($params);
returnarray(
'controller'=>$controller,
'action' =>$action,
'params' =>$params,
);
}
}
header("HTTP/1.0404NotFound");
exit('Pagenotfound');
}
}
$r=newRouter($route);
$arr=$r->parse($_GET['_url']);
require($arr['controller'].'.php');
//執行控制器的功能
$dispatcher=new$arr['controller'];
call_user_func_array(array($dispatcher,$arr['action']),$arr['params']);
?>
控制器1. Testcontroller.php
<?php
classTestController
{
publicfunctionidAction($id)
{
echo"Yourint-onlyidis:{$id}";
}
publicfunctionanyAction($any_id)
{
echo"Youanyidis:{$any_id}";
}
publicfunctionnoAction()
{
echo"Thismethodtakenoparameter";
}
}
默認控制器: IndexController.php
<?php
classIndexController
{
publicfunctionindexAction()
{
echo"HelloWorld!";
}
}
把.htaccess, index.php, TestController.php, IndexController.php放在htdoc里就可以了
H. thinkphp中路由表達式問題中"<>"和":"是什麼理解
<>包裹在TP裡面是組合變數
組合變數的優勢是路由規則中沒有固定的分隔符,可以隨意組合需要的變數規則和分割符,例如路由規則改成如下一樣可以支持:
Route::get('item<name><id>', 'proct/detail')->pattern(['name' => '[a-zA-Z]+', 'id' => 'd+']);
Route::get('item@<name>-<id>', 'proct/detail')->pattern(['name' => 'w+', 'id' => 'd+']);
I. 如何在PHP中實現URL路由
第一步,首先要在伺服器的配置上對/router/路徑進行攔截
調用某個文件夾目錄下的index.php頁面,假定現在所有模塊使用單獨的文件存放於class目錄下,該目錄與router平級,如下圖所示:
第二步,路由分發器的實現(index.php)
1: <!Doctype html>
2: <html>
3: <head>
4: <title>路由測試~~</title>
5: <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6: </head>
7: <body>
8:
9: <?php
10:
11: date_default_timezone_set("Asia/Shanghai");
12:
13: define("MODULE_DIR", "../class/");
14:
15:
16: $_DocumentPath = $_SERVER['DOCUMENT_ROOT'];
17: $_FilePath = __FILE__;
18: $_RequestUri = $_SERVER['REQUEST_URI'];
19:
20: $_AppPath = str_replace($_DocumentPath, '', $_FilePath); //==>\router\index.php
21: $_UrlPath = $_RequestUri; //==>/router/hello/router/a/b/c/d/abc/index.html?id=3&url=http:
22:
23: $_AppPathArr = explode(DIRECTORY_SEPARATOR, $_AppPath);
24:
25: /**
26: * http://192.168.0.33/router/hello/router/a/b/c/d/abc/index.html?id=3&url=http:
27: *
28: * /hello/router/a/b/c/d/abc/index.html?id=3&url=http:
29: */
30:
31: for ($i = 0; $i < count($_AppPathArr); $i++) {
32: $p = $_AppPathArr[$i];
33: if ($p) {
34: $_UrlPath = preg_replace('/^\/'.$p.'\//', '/', $_UrlPath, 1);
35: }
36: }
37:
38: $_UrlPath = preg_replace('/^\//', '', $_UrlPath, 1);
39:
40: $_AppPathArr = explode("/", $_UrlPath);
41: $_AppPathArr_Count = count($_AppPathArr);
42:
43: $arr_url = array(
44: 'controller' => 'index',
45: 'method' => 'index',
46: 'parms' => array()
47: );
48:
49: $arr_url['controller'] = $_AppPathArr[0];
50: $arr_url['method'] = $_AppPathArr[1];
51:
52: if ($_AppPathArr_Count > 2 and $_AppPathArr_Count % 2 != 0) {
53: die('參數錯誤');
54: } else {
55: for ($i = 2; $i < $_AppPathArr_Count; $i += 2) {
56: $arr_temp_hash = array(strtolower($_AppPathArr[$i])=>$_AppPathArr[$i + 1]);
57: $arr_url['parms'] = array_merge($arr_url['parms'], $arr_temp_hash);
58: }
59: }
60:
61: $mole_name = $arr_url['controller'];
62: $mole_file = MODULE_DIR.$mole_name.'.class.php';
63: $method_name = $arr_url['method'];
64:
65: if (file_exists($mole_file)) {
66: include $mole_file;
67:
68: $obj_mole = new $mole_name();
69:
70: if (!method_exists($obj_mole, $method_name)) {
71: die("要調用的方法不存在");
72: } else {
73: if (is_callable(array($obj_mole, $method_name))) {
74: $obj_mole -> $method_name($mole_name, $arr_url['parms']);
75:
76: $obj_mole -> printResult();
77: }
78: }
79:
80: } else {
81: die("定義的模塊不存在");
82: }
83:
84:
85: ?>
86:
87: </body>
88: </html>
獲取請求的uri,然後拿到要載入的模塊名、調用方法名,對uri參數進行簡單的判斷..
第三步,模塊的編寫
根據上述的uri,我們要調用的是Hello模塊下的router方法,那麼可以在class目錄下定義一個名為Hello.class.php的文件(注意linux下是區分大小寫的)
1: <?php
2:
3: class Hello {
4:
5: private $_name;
6: private $_varValue;
7:
8: function __construct() {
9:
10: }
11:
12: function router() {
13: $this->_name = func_get_arg(0);
14: $this->_varValue = func_get_arg(1);
15: }
16:
17: function printResult() {
18: echo $this->_name;
19: echo "<p>";
20: echo var_mp($this->_varValue);
21: echo "</p>";
22: }
23: }
24:
25: ?>
J. thinkphp5底層原理怎麼說
tp5是MVC框架,實現了視圖模型和控制器分離,希望能幫到你