Laravel 下因为 xdebug 对 404 返回超时变成 502 的奇怪问题?

环境在vagrant中,nginx和php-fpm配置都是常见的

  • php-5.6.21
  • nginx-1.8
  • laravel-5.2.45

昨天意外发现,xdebug开启的情况下,laravel下访问一个不存在路由(按理返回404报错页),却会一直卡死知道php-fpm被杀掉(显示为502)

经过追踪应该是xdebug.var_display_max_depth 设置太大(改小后正常了),好像导致调用出现死循环的问题。
但为何设置大了会死循环,还是不解;请大神指教!!


附配置及追踪输出:

  • xdebug 原来配置

    [xdebug]
    zend_extension=/home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_autostart=0
    xdebug.remote_port=9999
    xdebug.remote_host=10.0.2.2
    xdebug.idekey="PHPSTORM"
    xdebug.remote_handler=dbgp
    xdebug.default_enable = On
    xdebug.show_exception_trace = 0
    xdebug.collect_vars = On
    xdebug.collect_return = On
    xdebug.collect_params = On
    xdebug.var_display_max_depth = 15  #注意这个,官方默认是3
    xdebug.show_local_vars = 1
    xdebug.dump_undefined = 1
  • laravel gdb zbacktrace调用信息

    (gdb) source .gdbinit
    (gdb) zbacktrace
    [0x7f7fbe260fa8] match() /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:160
    [0x7f7fbe260c10] Illuminate\Routing\RouteCollection->match(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:821
    [0x7f7fbe2609c8] Illuminate\Routing\Router->findRoute(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:691
    [0x7f7fbe2606d0] Illuminate\Routing\Router->dispatchToRoute(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:675
    [0x7f7fbe260548] Illuminate\Routing\Router->dispatch(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:246
    [0x7fff620370b0] Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(object[0x7f7faa2e5540])
    [0x7f7fbe260368] call_user_func(object[0x7f7faa1e4e78], object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:52
    [0x7f7fbe260130] Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
    [0x7fff620380f0] Illuminate\View\Middleware\ShareErrorsFromSession->handle(object[0x7f7faa2e5540], object[0x7f7faa03e298])
    [0x7f7fbe25fe88] call_user_func_array(array(2)[0x7f7fa9f92f88], array(2)[0x7f7fa9f8d3c8]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
    [0x7fff62038c30] Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object[0x7f7faa2e5540])
    [0x7f7fbe25f9e8] call_user_func(object[0x7f7fa9f92fe8], object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
    [0x7f7fbe25f6f0] Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64
    [0x7fff62039c70] Illuminate\Session\Middleware\StartSession->handle(object[0x7f7faa2e5540], object[0x7f7fa9ffb050])
    [0x7f7fbe25f368] call_user_func_array(array(2)[0x7f7fa9fc61a0], array(2)[0x7f7fa9fc6ed8]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
    [0x7fff6203a7b0] Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object[0x7f7faa2e5540])
    [0x7f7fbe25eec8] call_user_func(object[0x7f7fa9fc6410], object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
    [0x7f7fbe25ebf0] Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:44
    [0x7fff6203b7f0] Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(object[0x7f7faa2e5540], object[0x7f7faa1a1d28])
    [0x7f7fbe25e9e8] call_user_func_array(array(2)[0x7f7faa08b550], array(2)[0x7f7fa9fc61d0]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:136
    [0x7fff6203c330] Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(object[0x7f7faa2e5540])
    [0x7f7fbe25e548] call_user_func(object[0x7f7fa9fafbf0], object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:32
    [0x7fff6203ce60] Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(object[0x7f7faa2e5540])
    [0x7f7fbe25e208] call_user_func(object[0x7f7fa9ff2f30], object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:103
    [0x7f7fbe25dfc0] Illuminate\Pipeline\Pipeline->then(object[0x7f7faa1e4e78]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:132
    [0x7f7fbe25dbb8] Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(object[0x7f7faa2e5540]) /vagrant/website/inncms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:99
    [0x7f7fbe25d7c0] Illuminate\Foundation\Http\Kernel->handle(object[0x7f7faa2e5540]) /vagrant/website/inncms/public/index.php:54
  • strace的io信息(显示内存不足被SIGSEGV kill掉)

    [vagrant@vagrant-centos65 php-5.6.21]$ strace -p 7539
    Process 7539 attached
    mremap(0x7f7fa616b000, 16494592, 969334784, MREMAP_MAYMOVE) = -1 EFAULT (Bad address)
    mmap(NULL, 969334784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
    brk(0x3b6af000)                         = 0x2a3c000
    mmap(NULL, 969469952, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
    mmap(NULL, 134217728, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, -1, 0) = 0x7f7f9e16b000
    munmap(0x7f7f9e16b000, 32067584)        = 0
    munmap(0x7f7fa4000000, 35041280)        = 0
    mprotect(0x7f7fa0000000, 135168, PROT_READ|PROT_WRITE) = 0
    mmap(NULL, 969334784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1 ENOMEM (Cannot allocate memory)
    --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0xfba677} ---
    +++ killed by SIGSEGV +++
  • pstack调用堆栈信息(显示xdebug调用较多)

    [vagrant@vagrant-centos65 conf]$ pstack 7539
    #0  0x00007fda30b6a6f2 in __strlen_sse42 () from /lib64/libc.so.6
    #1  0x00000000007bf45c in format_converter ()
    #2  0x00000000007bffbc in strx_printv ()
    #3  0x00000000007bffed in ap_php_vsnprintf ()
    #4  0x00007fda27b16487 in xdebug_sprintf () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #5  0x00007fda27b15181 in dump_used_var_with_contents () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #6  0x00007fda27b11974 in xdebug_hash_apply_with_argument () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #7  0x00007fda27b14db4 in xdebug_append_printable_stack () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #8  0x00007fda27b00b4a in xdebug_throw_exception_hook () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #9  0x0000000000835815 in zend_throw_exception_internal ()
    #10 0x000000000086779f in ZEND_THROW_SPEC_VAR_HANDLER ()
    #11 0x0000000000889c20 in execute_ex ()
    #12 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #13 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #14 0x0000000000889c20 in execute_ex ()
    #15 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #16 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #17 0x0000000000889c20 in execute_ex ()
    #18 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #19 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #20 0x0000000000889c20 in execute_ex ()
    #21 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #22 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #23 0x0000000000889c20 in execute_ex ()
    #24 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #25 0x000000000080d9e2 in zend_call_function ()
    #26 0x0000000000720eaf in zif_call_user_func ()
    #27 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #28 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #29 0x0000000000889c20 in execute_ex ()
    #30 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #31 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #32 0x0000000000889c20 in execute_ex ()
    #33 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #34 0x000000000080d9e2 in zend_call_function ()
    #35 0x0000000000721177 in zif_call_user_func_array ()
    #36 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #37 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #38 0x0000000000889c20 in execute_ex ()
    #39 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #40 0x000000000080d9e2 in zend_call_function ()
    #41 0x0000000000720eaf in zif_call_user_func ()
    #42 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #43 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #44 0x0000000000889c20 in execute_ex ()
    #45 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #46 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #47 0x0000000000889c20 in execute_ex ()
    #48 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #49 0x000000000080d9e2 in zend_call_function ()
    #50 0x0000000000721177 in zif_call_user_func_array ()
    #51 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #52 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #53 0x0000000000889c20 in execute_ex ()
    #54 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #55 0x000000000080d9e2 in zend_call_function ()
    #56 0x0000000000720eaf in zif_call_user_func ()
    #57 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #58 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #59 0x0000000000889c20 in execute_ex ()
    #60 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #61 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #62 0x0000000000889c20 in execute_ex ()
    #63 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #64 0x000000000080d9e2 in zend_call_function ()
    #65 0x0000000000721177 in zif_call_user_func_array ()
    #66 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #67 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #68 0x0000000000889c20 in execute_ex ()
    #69 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #70 0x000000000080d9e2 in zend_call_function ()
    #71 0x0000000000720eaf in zif_call_user_func ()
    #72 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #73 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #74 0x0000000000889c20 in execute_ex ()
    #75 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #76 0x000000000080d9e2 in zend_call_function ()
    #77 0x0000000000720eaf in zif_call_user_func ()
    #78 0x00007fda27b0169a in xdebug_execute_internal () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #79 0x000000000089a135 in zend_do_fcall_common_helper_SPEC ()
    #80 0x0000000000889c20 in execute_ex ()
    #81 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #82 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #83 0x0000000000889c20 in execute_ex ()
    #84 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #85 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #86 0x0000000000889c20 in execute_ex ()
    #87 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #88 0x000000000089a79c in zend_do_fcall_common_helper_SPEC ()
    #89 0x0000000000889c20 in execute_ex ()
    #90 0x00007fda27b01d93 in xdebug_execute_ex () from /home/vagrant/online/php-5.6.21/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
    #91 0x000000000081b409 in zend_execute_scripts ()
    #92 0x00000000007bac3a in php_execute_script ()
    #93 0x00000000008caa87 in main ()
公众号: newbmiao
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 4
leo

先做个试验,保持xdebug.var_display_max_depth = 15,然后新建一个测试路由对应到一个controller@action,这个action里直接抛出一个\Exception,看看是不是也是因为OOM而502

7年前 评论

@leo 你这么一说,我get到点了,应该是xdebug打印错误前下边设置会收集很多变量,而xdebug.var_display_max_depth = 15又设置了很大的深度,导致OOM了

xdebug.collect_vars = On
xdebug.collect_return = On
xdebug.collect_params = On
xdebug.show_local_vars = 1
xdebug.dump_undefined = 1

那么新的问题,这些信息收集是否必要?怎么设置合理些 :stuck_out_tongue:

7年前 评论
leo

@NewbMiao 根据具体调试的问题情况来决定是否打开吧

7年前 评论

@leo 高山仰止,景行行止,我和leo的技术的差距咋就这么大呢,THKS

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!