200 請求已成功,請求所希望的響應頭或數據體將隨此響應返回。 301 被請求的資源已永久移動到新位置,并且將來任何對此資源的引用都應該使用本響應返回的若干個 URI 之一。如果可能,擁有鏈接編輯功能的客戶端應當自動把請求的地址修改為從服務器反饋回來的地址。除非額外指定,否則這個響應也是可緩存的。 新的永久性的 URI 應當在響應的 Location 域中返回。除非這是一個 HEAD 請求,否則響應的實體中應當包含指向新的 URI 的超鏈接及簡短說明。 如果這不是一個 GET 或者 HEAD 請求,因此瀏覽器禁止自動進行重定向,除非得到用戶的確認,因為請求的條件可能因此發生變化。 注意:對于某些使用 HTTP/1.0 協議的瀏覽器,當它們發送的 POST 請求得到了一個301響應的話,接下來的重定向請求將會變成 GET 方式。
200 OK 一切正常,對GET和POST請求的應答文檔跟在后面。 301 Moved Permanently 客戶請求的文檔在其他地方,新的URL在Location頭中給出,瀏覽器應該自動地訪問新的URL 404 Not Found 無法找到指定位置的資源。這也是一個常用的應答。 502 Bad Gateway 服務器作為網關或者代理時,為了完成請求訪問下一個服務器,但該服務器返回了非法的應答。 503 Service Unavailable 服務器由于維護或者負載過重未能應答。例如,Servlet可能在數據庫連接池已滿的情況下返回503。服務器返回503時可以提供一個Retry-After頭。
10. 有如下數據庫, 用原生態mysql擴展去連接并查詢user表的前十行 host: 192.168.0.254 port: 3306 user: one pass: piece database: db_user table: user
$link = mysql_connect("192.168.0.254:3306","one","piece") or die('Could not connect: '.mysql_error()); mysql_select_db('db_user',$link); $query = mysql_query("select * from user limit 10"); while($rs = mysql_fetch_array($query,MYSQL_ASSOC)) {}
defined("CON_PATH","/data/wwwroot/www.xx.com/app/cntroller/"); $sb = new controller_sb(); ------------------------------------ function __autoload_my_classes($classname) { # ... your logic to include classes here } spl_autoload_register('__autoload_my_classes'); ----------------------------------------------------------- 12. 用set_error_handle 去捕獲錯誤并輸出, 級別自己定 set_error_handle(callback,level) function callback(int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] ){ }
function dealErrorHandler($errno,$errstr,$errfile,$errline) { switch($errno){ case E_USER_ERROR: echo "error [$errno] $errstr fatal error on line $errline in file $errfile"; break; case E_USER_WARNING: echo "my warning [$errno] $errstr": break; case E_USER_NOTICE: echo "my notice[$errno] $errstr"; break; default: echo "unkonwn error type :[$errno] $errstr"; break; } } set_erro_handler(dealErrorHandler);
i am here 1 總結 a.如果include或include_once不是在函數或方法中被調用,則輸出結果均一樣。 b.如果include或 include_once在函數或方法中被調用,則如果想讓第二次及以后調用時有結果,則必須用include,而不能用include_once,這一點一定要注意。
第二部分 1. 簡單實現一個單例+工廠的設計模式abstract class Example{ // The parameterized factory method public static function factory($type) { if (include_once 'Drivers/' . $type . '.php') { $classname = 'Driver_' . $type; return new $classname; } else { throw new Exception ('Driver not found'); } }}// Load a MySQL Driver$mysql = Example::factory('MySQL'); // Load a SQLite Driver $sqlite = Example::factory('SQLite'); definded('DRIVER','/data/wwwroot/www.want.com/core/driver/');abstract class Example(){ private function __construct() { } public static function factory($type) { if(include_once(DRIVER.$type.'.php')) { return ExampleSon::singleton($type); } else { throw new Exception("Driver is not found!"); } } }class ExampleSon implements Example{ // Hold an instance of the class private static $instance; //靜態私有的類實例 // A private constructor; prevents direct creation of object private function __construct() { echo 'I am constructed'; } // The singleton method public static function singleton() { if (!isset(self::$instance)) { //如果沒有設置靜態私有類實例,創建之 $c = __CLASS__; //獲得類名稱 self::$instance = new $c } return self::$instance; } // Example method public function bark() { echo 'Woof!'; } // Prevent users to clone the instance public function __clone() //不允許被克隆 { trigger_error('Clone is not allowed.', E_USER_ERROR); }}關鍵詞: 1 私有靜態成員變量 2 __CLASS__獲取當前類名 3 公共靜態方法獲取單例 4 覆蓋__clone()方法