本文介绍了使用Xdebug调试时启用OPcache时未显示局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启用了Xdebug,并与OPcache一起工作.首先由phpfpm(重要)加载OPcache模块.如果您尝试(从浏览器中)调试以下代码,并在本地变量中添加一个断点标记,您将看到它们未显示.如果我停用OPCache,一切都会按预期进行.我正在使用PhpStorm 2018.2.5进行调试.

I have Xdebug enabled and working together with OPcache. OPcache module is loaded first by phpfpm (important). If you try to debug the code below (from the browser) and put a breakpoing in the local variables you will see that they are not displayed. If I deactivate OPCache everything works as expected. I'm using PhpStorm 2018.2.5 to debug.

class Foo {
    public $member = 'Some value';

    public function methodFoo() {
        $localFoo = "local2";
    }
}

class Bar {
    public $firstMember = "foo";
    public $secondMember = "bar";

    public function create() {
        $localBar = 10;
        $newFoo = new Foo();
        $newFoo->methodFoo();
        $localBar += 1;
        $this->firstMember = "Other value";
    }

}

$foo = "testing";
$bar = "testing2";

$obj = new Bar();
$obj->create();

我不知道我是否错过了某件事,或者这是一个错误.多年前,xdebug中存在类似的错误,但与OPcache无关:错误

I do not know if I miss something or it's a bug. Years ago there was a similar bug in xdebug but it was not related to OPcache:bug

我保留与系统和Xdebug日志有关的信息

I leave the information related to my system and the log of Xdebug

phpinfo()
PHP Version => 7.2.10-0ubuntu0.18.04.1

System => Linux pablo-dv6 4.15.0-36-generic #39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86_64
Build Date => Sep 13 2018 13:45:02
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /etc/php/7.2/cli
Loaded Configuration File => /etc/php/7.2/cli/php.ini
Scan this dir for additional .ini files => /etc/php/7.2/cli/conf.d
Additional .ini files parsed => /etc/php/7.2/cli/conf.d/10-opcache.ini,
/etc/php/7.2/cli/conf.d/10-pdo.ini,
/etc/php/7.2/cli/conf.d/15-xml.ini,
/etc/php/7.2/cli/conf.d/20-calendar.ini,
/etc/php/7.2/cli/conf.d/20-ctype.ini,
/etc/php/7.2/cli/conf.d/20-curl.ini,
/etc/php/7.2/cli/conf.d/20-dom.ini,
/etc/php/7.2/cli/conf.d/20-exif.ini,
/etc/php/7.2/cli/conf.d/20-fileinfo.ini,
/etc/php/7.2/cli/conf.d/20-ftp.ini,
/etc/php/7.2/cli/conf.d/20-gettext.ini,
/etc/php/7.2/cli/conf.d/20-iconv.ini,
/etc/php/7.2/cli/conf.d/20-intl.ini,
/etc/php/7.2/cli/conf.d/20-json.ini,
/etc/php/7.2/cli/conf.d/20-mbstring.ini,
/etc/php/7.2/cli/conf.d/20-pdo_sqlite.ini,
/etc/php/7.2/cli/conf.d/20-phar.ini,
/etc/php/7.2/cli/conf.d/20-posix.ini,
/etc/php/7.2/cli/conf.d/20-readline.ini,
/etc/php/7.2/cli/conf.d/20-shmop.ini,
/etc/php/7.2/cli/conf.d/20-simplexml.ini,
/etc/php/7.2/cli/conf.d/20-sockets.ini,
/etc/php/7.2/cli/conf.d/20-sqlite3.ini,
/etc/php/7.2/cli/conf.d/20-sysvmsg.ini,
/etc/php/7.2/cli/conf.d/20-sysvsem.ini,
/etc/php/7.2/cli/conf.d/20-sysvshm.ini,
/etc/php/7.2/cli/conf.d/20-tokenizer.ini,
/etc/php/7.2/cli/conf.d/20-wddx.ini,
/etc/php/7.2/cli/conf.d/20-xmlreader.ini,
/etc/php/7.2/cli/conf.d/20-xmlwriter.ini,
/etc/php/7.2/cli/conf.d/20-xsl.ini,
/etc/php/7.2/cli/conf.d/20-zip.ini,
/etc/php/7.2/cli/conf.d/30-xdebug.ini

PHP API => 20170718
PHP Extension => 20170718
Zend Extension => 320170718
Zend Extension Build => API320170718,NTS
PHP Extension Build => API20170718,NTS
Debug Build => no
Thread Safety => disabled
Zend Signal Handling => enabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => available, disabled

Registered PHP Streams => https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters => zlib.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, convert.iconv.*

This program makes use of the Zend Scripting Language Engine:
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans


Zend OPcache

Opcode Caching => Disabled
Optimization => Disabled
SHM Cache => Enabled
File Cache => Disabled
Startup Failed => Opcode Caching is disabled for CLI

Directive => Local Value => Master Value
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.inherited_hack => On => On
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFFBFFF => 0x7FFFBFFF
opcache.preferred_memory_model => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On

与此部分相关的Xdebug日志(您可以看到没有出现$ localBar):

Xdebug log related to this part (you can see that $localBar doesn't appear):

<- context_get -i 46 -d 0 -c 0
-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="context_get" transaction_id="46" context="0"><property name="$newFoo" fullname="$newFoo" type="uninitialized"></property><property name="$this" fullname="$this" type="object" classname="Bar" children="1" numchildren="2" page="0" pagesize="100"><property name="firstMember" fullname="$this-&gt;firstMember" facet="public" type="string" size="3" encoding="base64"><![CDATA[Zm9v]]></property><property name="secondMember" fullname="$this-&gt;secondMember" facet="public" type="string" size="3" encoding="base64"><![CDATA[YmFy]]></property></property></response>

欢迎任何帮助,谢谢:)

Any help is welcome, thanks :)

推荐答案

我回答自己,以防它对某人有用.这是OPCache的功能.它有时会删除不需要的变量来优化PHP代码.解决方案:调试时禁用OPCache.

I answer myself, in case it serves to someone.This is a feature of OPCache. It optimizes PHP code by sometimes removing variables if they are not needed.Solution: disable OPCache when debugging.

sudo phpdismod opcache

然后根据您的环境重新启动phpfpm或apache

And restart phpfpm or apache according to your environment

sudo service php7.2-fpm restart

sudo service apache2 restart

更多信息此处.

这篇关于使用Xdebug调试时启用OPcache时未显示局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 08:25