linux - 怎樣讓 php 在 cli 與 fpm 環境下運行時載入不同的擴充 ?

來源:互聯網
上載者:User

問題:

由於開啟了 xdebug 擴充, 導致使用 composer 時提示:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

所以想在 cli 下不再載入 xdebug

環境:

  • linux 為 archlinux

  • php 通過 pacman 安裝, 版本 7.0.1

  • web服務通過 php-fpm 運行

設定檔分布:

/etc/php├── conf.d│   └── xdebug.ini├── fpm.d├── pear.conf├── php-fpm.conf├── php-fpm.d│   └── www.conf├── php.ini└── php.ini.pacnew

對比 ubuntu 下 通過 apt 安裝的 php 設定檔分布:

/etc/php5/├── cli│   ├── conf.d│   └── php.ini├── fpm│   ├── conf.d│   │   ├── 20-xdebug.ini -> ../../mods-available/xdebug.ini│   ├── php-fpm.conf│   ├── php.ini│   └── pool.d│       └── www.conf└── mods-available    └── xdebug.ini

---update ---

  • https://launchpadlibrarian.net/92790964/buildlog_ubuntu-hardy-amd64.php5_5.2.4-2ubuntu5.23_BUILDING.txt.gz

  • https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/php

不自行編譯安裝,重新指定各項config參數的情況下, 也只好手動指定 php.ini 運行了

回複內容:

問題:

由於開啟了 xdebug 擴充, 導致使用 composer 時提示:

You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug

所以想在 cli 下不再載入 xdebug

環境:

  • linux 為 archlinux

  • php 通過 pacman 安裝, 版本 7.0.1

  • web服務通過 php-fpm 運行

設定檔分布:

/etc/php├── conf.d│   └── xdebug.ini├── fpm.d├── pear.conf├── php-fpm.conf├── php-fpm.d│   └── www.conf├── php.ini└── php.ini.pacnew

對比 ubuntu 下 通過 apt 安裝的 php 設定檔分布:

/etc/php5/├── cli│   ├── conf.d│   └── php.ini├── fpm│   ├── conf.d│   │   ├── 20-xdebug.ini -> ../../mods-available/xdebug.ini│   ├── php-fpm.conf│   ├── php.ini│   └── pool.d│       └── www.conf└── mods-available    └── xdebug.ini

---update ---

  • https://launchpadlibrarian.net/92790964/buildlog_ubuntu-hardy-amd64.php5_5.2.4-2ubuntu5.23_BUILDING.txt.gz

  • https://projects.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/php

不自行編譯安裝,重新指定各項config參數的情況下, 也只好手動指定 php.ini 運行了

使用兩個不同的 php.ini 設定檔配置不同的運行參數(包括擴充參數),在開啟 cli 或者 fpm 時,通過 -c 參數指定運行所使用的 php.ini 即可。

PHP和PHP-FPM都可以用參數-c指定php.ini設定檔.

執行下列命令可見:

strace -f -o strace.log \/png/php/5.4.45/bin/php -v && \cat strace.log|egrep 'open|read'|grep 'ini'3080  open("/png/php/5.4.45/bin/php-cli.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3080  open("/png/php/5.4.45/lib/php-cli.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3080  open("/png/php/5.4.45/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3080  open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3

PHP會優先讀取php程式所在目錄下的php-cli.ini,訪問到則不再讀取其他ini檔案.
PHP-FPM情況如下:

strace -f -o strace.log \/png/php/5.4.45/sbin/php-fpm -v && \cat strace.log|egrep 'open|read'|grep 'ini'3537  open("/png/php/5.4.45/lib/php-fpm-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3537  open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3

PHP-CGI情況如下:

strace -f -o strace.log \/png/php/5.4.45/bin/php-cgi -v && \cat strace.log|egrep 'open|read'|grep 'ini'3568  open("./php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3568  open("/png/php/5.4.45/bin/php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3568  open("/png/php/5.4.45/lib/php-cgi-fcgi.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3568  open("./php.ini", O_RDONLY)       = -1 ENOENT (No such file or directory)3568  open("/png/php/5.4.45/bin/php.ini", O_RDONLY) = -1 ENOENT (No such file or directory)3568  open("/png/php/5.4.45/lib/php.ini", O_RDONLY) = 3

可以把cli目錄下的conf.d 的20-xdebug.ini 設定為禁用應該就可以了

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.