php 在 docker 里面可以通过 xdebug 连上宿主的 IDE 调试啊,做法类似这样:
```
@
unlink("/etc/php.d/xdebug.ini");
$my_xdebug = "/etc/php.d/my_xdebug.ini";
if(!file_exists($my_xdebug))
{
$HOST_IP=null;
exec("ip route", $o, $r);
echo implode(PHP_EOL, $o) . PHP_EOL;
foreach ($o as $line)
{
$res = preg_match("/default.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $line, $matches);
if($res)
$HOST_IP=$matches[1];
}
//$HOST_IP is not always correct. If wrong you should manually find your host's ip in container to use xdebug.
if(empty($HOST_IP))
{
die("failed to exec 'ip route' to get HOST's ip");
}
$xdebug_ini=<<<EOL
; Enable xdebug extension module
zend_extension=/usr/lib64/php/modules/
xdebug.soxdebug.remote_enable = 1
xdebug.remote_handler = "dbgp"
xdebug.remote_host = "{$HOST_IP}"
EOL;
```