4

In my normal projects, I use xdebug with phpstorm and it's great; I have no problem with it. However, in Magento2, using xdebug on my localhost is not possible because when xdebug remote is enabled in php.ini, Magento2 takes 1-2mins to load a page. It's totally frustrating.

Disabling the xdebug extension in php.ini will immediately increase the page load to about 5-10secs. Still slow, but better than minutes.

I've now resorted to print_r and logger everywhere in my code. But this is incredibly painful! More so when Magento reports that the error is coming from some factory which then I have to go in and mess up the core with all my print statements!

I've tried on 2 different computers and they both have the same issue with xdebug. First one is a Windows7 x64 8GB ram on an i5 processor. Second machine is a Windows10 x64 16GB ram on an i7 processor.

What is wrong with debugging Magento2 with xdebug? Ideally, I'd like to use a debugger. How can I fix this? Otherwise, how else can I debug when developing on Magento2?

  • You can list your system hardware? – Khoa TruongDinh Nov 29 '16 at 12:38
  • @KhoaTruongDinh Updated my question with my system specs. – xenon Nov 29 '16 at 12:44
  • Do you have all cached disabled? – KAndy Nov 29 '16 at 12:51
  • @KAndy All my cache are enabled. – xenon Nov 29 '16 at 12:52
  • Maybe you use Magento on VirtualBox? 10 secs it's too slow even for enabled xdebug – KAndy Nov 29 '16 at 12:59
3

This might not be the best solution, however, its the way I debug stuff on Magento 2.

First of all, switch to Developer mode. You can do this via the console:

$ php bin/magento deploy:mode:set developer

Magento2 by default install in “default” mode and thats why you dont get the error log at the front-end of the site , that can a viewed at magento error log . You may check the complete details over here http://devdocs.magento.com/guides/v2.0/config-guide/bootstrap/magento-modes.html

also, you can modify your .htaccessfile and remove the dash from the first parameter, which will enable developer mode as well. DONT FORGET TO CHANGE THIS ONCE YOU GO LIVE

Whilst in Developer mode, errors are shown to the user, also the logging is more verbose.

Another thing you can do is to go into you index.php and add PHP-error reporting lines.

error_reporting(E_ALL);
ini_set('display_errors', 1);

If you're still having troubles, try to rename the local.xml.sample to local.xml in pub/errors/.

Hope this helps you a little.

| improve this answer | |
  • This is exactly what I'm doing. Sometimes, I don't just want to see error. I want to find out what's the value in certain variables along the flow and a debugger is very helpful for this. – xenon Nov 29 '16 at 12:45
  • Ah, I understand. Basically I misunderstood your question then a little. Hope it helps anyway. – Max Nov 29 '16 at 13:12
  • 1
    No worries! I'm sure your answer is still going to help others who later come across this question! :) – xenon Nov 29 '16 at 13:14
  • That's the spirit. :) – Max Nov 29 '16 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.