linux - 怎样让 php 在 cli 与 fpm 环境下运行时加载不同的扩展 ?
伊谢尔伦
伊谢尔伦 2017-04-10 16:37:00
[PHP讨论组]

问题:

由于开启了 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伐。

全部回复(3)
ringa_lee

使用两个不同的 php.ini 配置文件配置不同的运行参数(包括扩展参数),在开启 cli 或者 fpm 时,通过 -c 参数指定运行所使用的 php.ini 即可。

PHP中文网

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 设置为禁用应该就可以了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号