Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

george1's avatar

How to Fix PHP and Laravel consuming 100% of my CPU every time I load my website locally?

Out of the sudden, laravel and PHP 7.3.31:

PHP 7.3.31 (cli) (built: Sep 25 2021 08:05:33) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.31, Copyright (c) 1998-2018 Zend Technologies
    with Xdebug v2.9.0, Copyright (c) 2002-2019, by Derick Rethans
    with Zend OPcache v7.3.31, Copyright (c) 1999-2018, by Zend Technologies

Is taking up 100% of my CPU usage and every time I load my website, the refresh is EXTREMELY slow.

I tried getting a sample of what's going on in the process and I saw this:

Call graph:
    2556 Thread_36283   DispatchQueue_1: com.apple.main-thread  (serial)
      2556 start  (in libdyld.dylib) + 1  [0x7fff2053ef3d]
        2556 main  (in php) + 1424  [0x10d0a5d7a]
          2556 do_cli_server  (in php) + 2332  [0x10d0ab5d7]
            2556 php_cli_server_do_event_for_each_fd_callback  (in php) + 153  [0x10d0ad3bf]
              2556 php_cli_server_recv_event_read_request  (in php) + 612  [0x10d0ac943]
                2556 php_cli_server_dispatch_router  (in php) + 202  [0x10d0ae7f2]
                  2556 zend_execute_scripts  (in php) + 269  [0x10cffd853]
                    2556 zend_execute  (in php) + 317  [0x10d037a02]
                      2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                        2556 execute_ex  (in php) + 45  [0x10d037853]
                          2556 ZEND_INCLUDE_OR_EVAL_SPEC_CONST_HANDLER  (in php) + 583  [0x10d06bc2b]
                            2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                              2556 execute_ex  (in php) + 45  [0x10d037853]
                                2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                  2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                    2556 execute_ex  (in php) + 45  [0x10d037853]
                                      2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                        2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                          2556 execute_ex  (in php) + 45  [0x10d037853]
                                            2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                              2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                2556 execute_ex  (in php) + 45  [0x10d037853]
                                                  2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                    2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                      2556 execute_ex  (in php) + 45  [0x10d037853]
                                                        2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                          2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                            2556 execute_ex  (in php) + 45  [0x10d037853]
                                                              2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                  2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                    2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                      2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                        2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                          2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                            2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                              2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                  2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                    2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                      2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                        2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                          2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                            2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                              2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                  2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                                    2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                      2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                        2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                                          2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                            2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                              2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                                                2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                                  2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                                    2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                                                      2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                                        2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                                          2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  [0x10d067e4b]
                                                                                                                            2556 xdebug_execute_ex  (in xdebug.so) + 1060  [0x10ed76154]
                                                                                                                              2556 execute_ex  (in php) + 45  [0x10d037853]
                                                                                                                                2556 ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER  (in php) + 411  

Unfortunately, I am not a pro to understand what this is, but I got it as a sample from the Mac OS Activity Monitor. How can I fix this problem?

0 likes
13 replies
aurawindsurfing's avatar
Level 50

It looks like you activated xdebug - disable it and see it it will get back to normal.

I'm not big fan of xdebug as i always coused issues for myself.

1 like
aurawindsurfing's avatar

@george1 If its not xdebug - since you say you did not try to activate it, I would look for a loop in your code that is causing it.

Can you display simple "Hello World"? How many processes you see run by PHP and how much memory does each one consume?

george1's avatar

@aurawindsurfing Yes, the entire website loads, but only after 100% of cpu usage and 3 minutes. How do I check the processes? Sorry, I am really not an PHP Expert...

george1's avatar

@aurawindsurfing IT only shows this:

[Wed Sep 29 18:50:37 2021] 127.0.0.1:51596 [200]: /favicon.ico
[Wed Sep 29 18:50:37 2021] 127.0.0.1:51602 [200]: /favicon.ico
[Wed Sep 29 18:50:42 2021] 127.0.0.1:51604 [200]: /favicon.ico
[Wed Sep 29 18:50:44 2021] 127.0.0.1:51608 [200]: /favicon.ico
[Wed Sep 29 18:50:44 2021] 127.0.0.1:51612 [200]: /favicon.ico
[Wed Sep 29 18:50:45 2021] 127.0.0.1:51619 [200]: /favicon.ico
[Wed Sep 29 18:50:46 2021] 127.0.0.1:51624 [200]: /favicon.ico
[Wed Sep 29 18:50:46 2021] 127.0.0.1:51628 [200]: /favicon.ico
[Wed Sep 29 18:50:59 2021] 127.0.0.1:51632 [200]: /favicon.ico
[Wed Sep 29 18:51:13 2021] 127.0.0.1:51637 [200]: /favicon.ico
[Wed Sep 29 18:51:25 2021] 127.0.0.1:51642 [200]: /favicon.ico
[Wed Sep 29 18:51:34 2021] 127.0.0.1:51646 [200]: /favicon.ico
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51651 [200]: /css/main.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51653 [200]: /css/blog.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51657 [200]: /css/comments.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51654 [200]: /css/articles.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51655 [200]: /css/subscribe_form.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51656 [200]: /css/mobile_soc_med.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51658 [200]: /css/comment_settings.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51659 [200]: /js/fb.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51660 [200]: /images/blog/article-36/cover.webp
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51661 [200]: /images/soc_med_icons/Icons/256/Facebook.png
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51662 [200]: /images/soc_med_icons/Icons/256/Twitter.png
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51663 [200]: /images/soc_med_icons/Icons/256/Youtube.png
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51664 [200]: /images/profile_pics/85-prof-img.png
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51665 [200]: /js/lazysizes.min.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51666 [200]: /js/adblock_detection.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51667 [200]: /js/tweet_popup.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51668 [200]: /js/articles.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51669 [200]: /js/img_slideshow.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51670 [200]: /js/blog.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51671 [200]: /js/blog_ajax.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51672 [200]: /js/main.js
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51673 [200]: /css/adblock_detection.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51674 [200]: /css/tweet_popup.css
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51675 [200]: /images/techlunar%20logo%20white.svg
[Wed Sep 29 18:51:49 2021] 127.0.0.1:51676 [200]: /images/techlunar%20logo%20white.svg
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51690 [200]: /images/techlunar_fav.png
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51692 [200]: /images/blog/article-29/cover.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51705 [200]: /images/blog/article-54/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51707 [200]: /images/blog/article-55/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51709 [200]: /images/blog/article-56/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51712 [200]: /images/blog/article-57/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51713 [200]: /images/blog/article-58/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51714 [200]: /images/blog/article-77/cover_240.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51715 [200]: /images/blog/article-29/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51716 [200]: /images/blog/article-70/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51717 [200]: /images/blog/article-64/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51718 [200]: /images/blog/article-55/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51719 [200]: /images/blog/article-63/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51720 [200]: /images/blog/article-58/cover_120.webp
[Wed Sep 29 18:53:39 2021] 127.0.0.1:51721 [200]: /favicon.ico
[Wed Sep 29 18:54:03 2021] 127.0.0.1:51723 [200]: /favicon.ico
[Wed Sep 29 18:55:13 2021] 127.0.0.1:51742 [200]: /favicon.ico
george1's avatar

@aurawindsurfing Ok , I dug a bit further and I think PHP is EXTREMELY SLOW when it's loading anything that has to do with mysql, so when PHP has to request data from the database it's causing this 100% issue, but I still don't know how and why

george1's avatar

@aurawindsurfing LEGEND! You were right about xdebug. There is the PHP extention called xdebug.so which was enabled by default in php.ini. For those who experience the same issue (or similar) do the following:

  1. type php --ini in terminal to find the PHP ini file path.
  2. open php.ini and comment (or remove) the line zend_extension="xdebug.so" or any other line including xdebug.
  3. run php artisan optimize:clear to clean your cache.

Issue fixed! However I still don't know the following:

  1. What is xdebug and what does it do?
  2. Why was it causing this Problem? I Googled it and it seems a segfault issue but couldn't find out why and how?
  3. Why and how xdebug is causing this issue?

I would love to find out the answers above if someone knows!

aurawindsurfing's avatar

@george1 xdebug is kind of like a proxy that will capture everything your PHP server is doing and let you look at it (debug it).

I would not try to install more stuff, telecsope is fine but simple https://github.com/barryvdh/laravel-debugbar will show you everything you need. There is a bottleneck somewhere and I doubt it is database. It could be however lots of queries to database like N+1 problem for instance.

I would install debugbar and try to figure out what is taking so long to load, also try using developer tools in your browser and see the "Network" tab - you will see what resources are loaded and when.

Hope it helps!

george1's avatar

@frankielee Ok, installed it and I looked into the processes. However, all the queries seem to run in less than 1ms. A couple of them take 40ms. I still can't understand and find what's causing this issue.

frankielee's avatar

@george1 Maybe is the view rendering part? Just create a route that return plain text and monitor the usage.

Example:

Route::get('/test',function(){
	return "test";
});
george1's avatar

@frankielee Ok, I have now pushed the website on my VPS and it's very fast when I request every single page from my website online. The local version is the one which is being EXTREMELY slow. I have tried your example and it seems to be fast, but pages where loading from the database are the ones which are extremely slow.

Please or to participate in this conversation.