0

My Config:

  • CakePHP Version: 3.6.13
  • Platform and Target: PHP 7.2, MySQL 5.7, Ubuntu 16.04.5 LTS, Vagrant, Apache, php-fpm, PhpStorm 2019.1 EAP

php -v output

PHP 7.2.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Dec  7 2018 08:07:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans

xdebug config

/etc/php/7.2/cli/conf.d/99-xdebug.ini,
xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.coverage_enable => On => On
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.filename_format => no value => no value
xdebug.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.gc_stats_enable => Off => Off
xdebug.gc_stats_output_dir => /tmp => /tmp
xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
xdebug.max_nesting_level => 256 => 256
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => On => On
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /tmp => /tmp
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => 10.0.2.2 => 10.0.2.2
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.remote_timeout => 200 => 200
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /tmp => /tmp
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

Originally I posted what I thought was a bug in cakephp on GitHub.

See https://github.com/cakephp/cakephp/issues/13020

In summary, it appeared that foreach was not iterating over a Traversable object containing the results of a db query. I confirmed there were results to iterate by first converting the object to an array and inspection of the object in the debugger shows there were items to iterate over. After converting to array, the foreach iterates over the elements as expected.

When I disabled listening on xdebug, foreach will iterate over the Traversable object as expected, without first converting to an array.


I have tried setting xdebug.collect_params=1 as @Asgraf suggested in my original post, but that did not fix anything.


When I try to evaluate the first element in the Traversable object in the debugger, before foreach loop below, execution exits immediately.

        $mapper = $this->_mapper;

        foreach ($this->_data as $key => $val) {
            $mapper($val, $key, $this);
        }

Example of foreach loop with failing execution in debugger

Below is the hierarchy of ResultSet if it helps provide some clarity.

Class hierarchy of ResultSet

Any insight as to what is going on or how to fix this odd behavior would be greatly appreciated.


UPDATE with logging

PhpStorm Log

2019-02-26 12:13:21,241 [ 967833]  DEBUG - il.connection.ServerConnection - Incoming connection on port 9000 from 127.0.0.1 
2019-02-26 12:13:21,247 [ 967839]  DEBUG - .connection.PhpDebugConnection - 1709495916#----connection started 
2019-02-26 12:13:21,332 [ 967924]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@294dfd25 
2019-02-26 12:13:21,332 [ 967924]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@1d499b6f 
2019-02-26 12:13:21,336 [ 967928]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64 
2019-02-26 12:13:21,336 [ 967928]  DEBUG - .php.run.filters.PhpUnitFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64 
2019-02-26 12:13:21,336 [ 967928]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpRemotePathMapper@25da7f64 
2019-02-26 12:13:21,482 [ 968074]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# Stop at ('file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php':177) 
2019-02-26 12:13:21,482 [ 968074]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> local: '/Users/myorkgitis/Documents/phpstorm-workspace/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' 
2019-02-26 12:13:21,483 [ 968075]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> extracted: '/var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' 
2019-02-26 12:13:21,509 [ 968101]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@2f1cc1ce 
2019-02-26 12:13:21,510 [ 968102]  DEBUG - ains.php.run.filters.PhpFilter - Path mapper: com.jetbrains.php.util.pathmapper.PhpIdenticalPathMapper@484b8985 
2019-02-26 12:13:30,780 [ 977372]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# Stop at ('file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php':178) 
2019-02-26 12:13:30,780 [ 977372]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> local: '/Users/myorkgitis/Documents/phpstorm-workspace/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' 
2019-02-26 12:13:30,780 [ 977372]  DEBUG - p.debug.common.PhpDebugProcess - 1947777361# remote: 'file:///var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' <-> extracted: '/var/www/at/vendor/cakephp/cakephp/src/Collection/Iterator/MapReduce.php' 
2019-02-26 12:13:37,262 [ 983854]  DEBUG - .connection.PhpDebugConnection - 1709495916#---input stream is finished 
2019-02-26 12:13:37,262 [ 983854]  DEBUG - .connection.PhpDebugConnection - 1709495916#---stop reading 
2019-02-26 12:13:37,262 [ 983854]  DEBUG - .connection.PhpDebugConnection - 1709495916#---stop writing 
2019-02-26 12:13:37,262 [ 983854]  DEBUG - .connection.PhpDebugConnection - 1709495916#----connection stopped 
2019-02-26 12:13:37,263 [ 983855]  DEBUG - il.connection.ServerConnection - ----socket closed 

xdebug log

The xdebug log doesn't have anything interesting. There are no references to an exception or an error.

Here are the last few entries, which look harmless except for the fact that the log closes right after the run command...

-> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="22" status="stopping" reason="ok"></response>

<- run -i 23
Log closed at 2019-02-26 17:27:27

Some other things to note

The script does iterate over the first element, but it exits the foreach loop right after and continues the rest of the request, returning data to the view (but of course with only one result, instead of the expected 10)

I have also tested on PhpStorm 2018.3 and 2018.4 and the behavior persists.

nightcoder
  • 43
  • 5
  • 1) Collect xdebug log for such debug session and see how it ends 2) check PhpStorm's log (`idea.log`) to see the same (you may need to enable extra logging for that: https://intellij-support.jetbrains.com/hc/en-us/articles/207241115-How-to-Collecting-PhpStorm-WebStorm-debug-Logs Purelly from such general description... it's possible that Xdebug crashes for some reason. Or it could be the IDE that catches some exception. – LazyOne Feb 26 '19 at 15:23
  • Thanks @LazyOne. I have looked into the logs, but don't see anything that looks problematic. – nightcoder Feb 26 '19 at 18:06
  • Sounds like Xdebug / PHP crash to me. See if you can find such details in appropriate logs (sorry, not a Linux user); see xdebug website as to where such logs might be/how to get that info (if it's the case, of course). Perhaps php-fpm will have some info about that? – LazyOne Feb 26 '19 at 18:15

0 Answers0