<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## **Request** ``` // $connection TcpConnection對象 // $session Session 實例 // $properties // ::$maxFileUploads 上傳文件最大size,默認1024 // __construct($buffer) // get($name = null, $default = null) // post($name = null, $default = null) // header($name = null, $default = null) // cookie($name = null, $default = null) // file($name = null) // method() // protocolVersion() // host($without_port = false) // uri() // path() // queryString() // session() // sessionId($session_id = null) // rawHead() // rawBody() // rawBuffer() // ::enableCache($value) 開啟關閉緩存 // __set($name, $value) // __get($name) // __isset($name) // __unset($name) // __toString() // __wakeup() // __destruct() ``` ``` //use Workerman\Worker; use Workerman\Connection\TcpConnection; use Workerman\Protocols\Http\Request; $worker = new Worker('http://0.0.0.0:8080'); $worker->onMessage = function(TcpConnection $connection, Request $request) { $get = $request->get(); $get_user = $request->get("user",'tom'); // $request為請求對象 $connection->send("hello " . $get_user); }; // 運行worker Worker::runAll(); ``` ## **get()** ``` $get_params = $request->get(); $get_pwd = $request->get("pwd"); //可以給get參數一個默認值 $get_pwd = $request->get("pwd",'admin123456'); ``` ## **post()** ``` $post_params = $request->post(); $post_pwd = $request->post("pwd"); //可以給post參數一個默認值 $post_pwd = $request->post("pwd",'admin123456'); ``` ## **rawBody()** 獲得原始請求post包體 這個功能類似與`php-fpm`里的`file_get_contents("php://input");`操作。用于獲得http原始請求包體。這在獲取非`application/x-www-form-urlencoded`格式的post請求數據時很有用 ``` $post = $request->rawBody(); ``` 示例: ``` use Workerman\Worker; use Workerman\Connection\TcpConnection; use Workerman\Protocols\Http\Request; require_once __DIR__ . '/vendor/autoload.php'; $worker = new Worker('http://0.0.0.0:8080'); $worker->onMessage = function(TcpConnection $connection, Request $request) { $post = json_decode($request->rawBody()); $connection->send('hello'); }; // 運行worker Worker::runAll(); ``` ## **header()** 獲取header ``` // 獲取整個header數組 $header_params= $request->header(); // 獲取header數組的某一個值 $header= $request->header('host'); //可以給header參數一個默認值 $header= $request->header('host', 'localhost'); ``` ## **cookie()** 獲取cookie ``` // 獲取整個cookie數組 $cookie_params= $request->cookie(); // 獲取cookie數組的某一個值 $cookie= $request->cookie('name'); //可以給cookiet參數一個默認值 $cookie= $request->cookie('name', 'tom'); ``` ## **file()** 獲取上傳文件 返回的文件格式類似: ~~~php array ( 'avatar' => array ( 'name' => '123.jpg',// name為文件名字 'tmp_name' => '/tmp/workerman.upload.9hjR4w',// tmp_name為磁盤臨時文件位置 'size' => 1196127,// size為文件大小 'error' => 0, // error為錯誤碼 'type' => 'application/octet-stream', // type為文件mine類型 ), 'anotherfile' => array ( 'name' => '456.txt', 'tmp_name' => '/tmp/workerman.upload.9sirSws', 'size' => 490, 'error' => 0, 'type' => 'text/plain', ) ) ~~~ error[錯誤碼](https://www.php.net/manual/zh/features.file-upload.errors.php) >[danger]**注意:** >* 上傳文件大小受到[defaultMaxPackageSize](https://www.workerman.net/doc/workerman/tcp-connection/default-max-package-size.html)限制,默認10M,可修改。 >* 請求結束后文件將被自動清除。 >* 如果請求沒有上傳文件則返回一個空的數組。 ### 獲取特定上傳文件 ~~~php $avatar_file = $request->file('avatar'); ~~~ 返回類似 ~~~php array ( 'name' => '123.jpg', 'tmp_name' => '/tmp/workerman.upload.9hjR4w', 'size' => 1196127, 'error' => 0, 'type' => 'application/octet-stream', ) ~~~ 如果上傳文件不存在則返回null。 **例子** ~~~php use Workerman\Worker; use Workerman\Connection\TcpConnection; use Workerman\Protocols\Http\Request; require_once __DIR__ . '/vendor/autoload.php'; $worker = new Worker('http://0.0.0.0:8080'); $worker->onMessage = function(TcpConnection $connection, Request $request) { $file = $request->file('avatar'); if ($file && $file['error'] === UPLOAD_ERR_OK) { rename($file['tmp_name'], '/home/www/web/public/123.jpg'); $connection->send('ok'); return; } $connection->send('upload fail'); }; // 運行worker Worker::runAll(); ~~~ ##** host()** 獲取host ``` 獲取請求的host信息 $host = $request->host(); //不返回host信息攜帶端口 $host = $request->host(true); ``` ## **method()** 獲取請求方法 返回值可能是GET、POST、PUT、DELETE、OPTIONS、HEAD中的一個。 ``` $method = $request->method(); ``` ## **uri()** 獲取請求uri (如:/user/get.php?uid=10&type=2) 返回請求的uri,包括path和queryString部分。 ``` //當瀏覽器訪問`http://127.0.0.1:8080/user/get.php?uid=10&type=2`時將返回`/user/get.php?uid=10&type=2` $uri = $request->uri(); ``` ## **path()** 獲取請求路徑(如:/user/get.php) 返回請求的path部分 ``` //當瀏覽器訪問`http://127.0.0.1:8080/user/get.php?uid=10&type=2`時將返回`/user/get.php` $path = $request->path(); ``` ## **queryString()** 獲取請求queryString(如:uid=10&type=2) ``` //當瀏覽器訪問`http://127.0.0.1:8080/user/get.php?uid=10&type=2`時將返回`uid=10&type=2` $query_string = $request->queryString(); ``` ## **protocolVersion()** 獲取請求HTTP版本(返回字符串 1.1 或者1.0) ``` $version = $request->protocolVersion(); ``` ## **sessionId()** 獲取請求sessionId 返回字符串,由字母和數字組成 ``` $sid = $request->sessionId(); ``` ## **session()** 返回\Workerman\Protocols\Http\Session對象 ## **rawHead()** 獲取http原始頭 ## **rawBuffer()** 獲取http原始緩沖區 ## **::enableCache($value) 開啟關閉請求緩存 默認true** 傳入的參數最終回強制轉換為bool,如:static::$_enableCache = (bool)$value; ``` Request::enableCache(1) Request::enableCache(true) ``` ## **::$maxFileUploads** 上傳文件最大size,默認1024
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看