乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      利用 PHP 快速建立一個(gè) Web 服務(wù)器

       代碼小伙兒 2021-02-14

      從 PHP 5.4.0 起, CLI SAPI 提供了一個(gè)內(nèi)置的 Web 服務(wù)器。我們可以通過這個(gè)內(nèi)置的 Web 服務(wù)器很方便的搭建一個(gè)本地開發(fā)環(huán)境。

      • 啟動(dòng) Web 服務(wù)器

      默認(rèn)情況下,URI 請(qǐng)求會(huì)被發(fā)送到 PHP 所在的的工作目錄進(jìn)行處理。

      $ cd /tmp/wordpress-install $ php -S localhost:8000 PHP 7.1.16 Development Server started at Mon Jun  4 16:48:42 2018 Listening on http://localhost:8000 Document root is /private/tmp/wordpress-install Press Ctrl-C to quit.

      如果請(qǐng)求未指定執(zhí)行 PHP 文件,則默認(rèn)執(zhí)行目錄內(nèi)的 index.php 或者 index.html。如果這兩個(gè)文件都不存在,服務(wù)器會(huì)則返回 404 錯(cuò)誤。

      接著通過瀏覽器打開 http://localhost:8000/ 就可訪問對(duì)應(yīng)的 Web 程序,在終端窗口會(huì)輸出類似以下的訪問日志:

      [Mon Jun  4 16:50:55 2018] ::1:54854 [302]: / [Mon Jun  4 16:50:55 2018] ::1:54855 [200]: /wp-admin/setup-config.php [Mon Jun  4 16:50:55 2018] ::1:54858 [200]: /wp-includes/css/buttons.min.css?ver=4.9.4 [Mon Jun  4 16:50:55 2018] ::1:54860 [200]: /wp-includes/js/jquery/jquery.js?ver=1.12.4 [Mon Jun  4 16:50:55 2018] ::1:54859 [200]: /wp-admin/css/install.min.css?ver=4.9.4 [Mon Jun  4 16:50:55 2018] ::1:54861 [200]: /wp-includes/js/jquery/jquery-migrate.min.js?ver=1.4.1 [Mon Jun  4 16:50:55 2018] ::1:54862 [200]: /wp-admin/js/language-chooser.min.js?ver=4.9.4 [Mon Jun  4 16:50:56 2018] ::1:54863 [200]: /wp-admin/images/wordpress-logo.svg?ver=20131107 [Mon Jun  4 16:50:57 2018] ::1:54864 [404]: /favicon.ico - No such file or directory
      • 啟動(dòng)時(shí)指定根目錄

      如果要自定義啟動(dòng)根目錄,你可以使用 -t 參數(shù)來自定義不同的目錄。

      $ cd /tmp/wordpress-install $ php -S localhost:8000 -t wp-admin/ PHP 7.1.16 Development Server started at Mon Jun  4 16:53:55 2018 Listening on http://localhost:8000 Document root is /private/tmp/wordpress-install/wp-admin Press Ctrl-C to quit. [Mon Jun  4 16:54:04 2018] ::1:54912 [302]: /
      • 使用路由腳本

      默認(rèn)情況下,PHP 建立的 Web 服務(wù)器會(huì)由 index.php 接收所有請(qǐng)求參數(shù)。如果要讓指定的 PHP 文件來處理請(qǐng)求,可以在啟動(dòng)這個(gè) Web 服務(wù)器時(shí)直接指定要處理請(qǐng)求的文件名。這個(gè)文件會(huì)作為一個(gè)路由腳本,意味著每次請(qǐng)求都會(huì)先執(zhí)行這個(gè)腳本。(通常將此文件命名為 router.php)

      下面我們來看一個(gè)例子,請(qǐng)求圖片直接顯示圖片,請(qǐng)求 HTML 則顯示 “Welcome to PHP”。

      $ vim router.php  <?php // router.php if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) return false;    // 直接返回請(qǐng)求的文件 else { echo "<p>Welcome to PHP</p>"; } ?>

      執(zhí)行后,訪問 HTML 文件就會(huì)在終端窗口輸出對(duì)應(yīng)的 HTML 代碼。

      $ php -S localhost:8000 router.php PHP 7.1.16 Development Server started at Mon Jun  4 17:00:19 2018 Listening on http://localhost:8000 Document root is /private/tmp/wordpress-install Press Ctrl-C to quit.  $ curl http://localhost:8000/index.html <p>Welcome to PHP</p>%

      接下來,我們?cè)诳纯丛L問圖片。訪問圖片后就會(huì)在終端窗口輸出類似以下的訪問日志:

      [Mon Jun  4 17:00:39 2018] ::1:55008 [200]: /wp-content/themes/twentyseventeen/assets/images/coffee.jpg [Mon Jun  4 17:00:57 2018] ::1:55034 [200]: /wp-content/themes/twentyseventeen/assets/images/espresso.jpg [Mon Jun  4 17:01:08 2018] ::1:55035 [200]: /wp-content/themes/twentyseventeen/assets/images/header.jpg [Mon Jun  4 17:01:16 2018] ::1:55037 [200]: /wp-content/themes/twentyseventeen/assets/images/sandwich.jpg

      今日思想

      不能忍受生命中注定要忍受的事情,就是軟弱和愚蠢的表現(xiàn)。

      —— 勃朗特

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多