Skip to content

Instantly share code, notes, and snippets.

@erikhansen
Last active December 6, 2023 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikhansen/aa4a2afe866fa3bbb375cbbde14861a0 to your computer and use it in GitHub Desktop.
Save erikhansen/aa4a2afe866fa3bbb375cbbde14861a0 to your computer and use it in GitHub Desktop.
Troubleshoot long-running PHP script in Magento 2 on Warden

For future reference:

I just had to troubleshoot a script that ran so long that it eventually died without any relevant errors ([pid 6048:tid 139809649469184] (104)Connection reset by peer: [client 184.4.89.70:0] FastCGI: comm with server "/var/run/a49982b9-remi-safe-php81.fcgi" aborted: read failed, referer was getting written to the Apache error logs).

Thankfully I was able to reproduce the issue locally. Here are the steps I took in Warden to troubleshoot:

In pub/index.php I added this line: set_time_limit(15); above the $bootstrap->run($app);

cd <PATH TO MAGENTO 2 DIRECTORY>

# I then reproduced the error on my frontend, ensuring that the 15 second time limit had been hit
# Then, I enabled the "Profile" option in the Xdebug helper: https://take.ms/1HYDh
# Reload the frontend to generate the cachegrind profile
# Now, copy the cachegrind file to a place where it will sync to the host Mac machine

warden env exec php-debug bash
ls -lha /tmp/
mv /tmp/cachegrind.out.1701815273._var_www_html_pub_index_php__customer_account_index_.gz /var/www/htm

# Now, on my Mac
brew install qcachegrind
qcachegrind
# Now, open the <PATH TO MAGENTO 2 DIRECTORY> cachegrind.out.1701815273._var_www_html_pub_index_php__customer_account_index_.gz file

In qcachegrind, you can analyze what code was run to find the issue:

i… 2023-12-06 11-09-44

MCG is another option for a cachegrind GUI: http://mcg-app.com/

I find its UI a little easier to navigate:

cachegrind out 1701815273 var_www_html_pub_index_php__customer_account_index 2023-12-06 11-11-48

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment