I'm trying to speed up my wordpress site because for some reason it's taking on average 5 seconds to load a page (obviously way too slow). I've tracked it down to the php-cgi.exe hogging an incredibly large amount of cpu time, but now have no idea how to figure out why or how to fix it. Any ideas how I could debug the php-cgi.exe and figure out what is slowing it down?
PHP itself should definitely not be doing that. Are you sure it is PHP, and not the script you are running?
Try a simple Hello World script and see if you notice the same behavior:
<?php echo "Yellow World"; ?>
If you do, try calling it from the command line and see if you have the same problem:
php.exe helloworld.php
If the CLI version executes nice and fast, but the web based one doesn't, you can begin digging into the trouble between your web server and PHP.
Finally, check and make sure a broken or misconfigured extension isn't hanging things up. Remove all extensions you don't need. If you still have trouble, remove them all and add them back in one by one.
Switched to a shared Linux server. All of a sudden everything works without a hitch... start microsoft bashing... now.
Related
Good Evening Everyone,
I've been learning PHP and I'm using the built in server to learn the syntax and running simple scripts and web pages. I've been going at it for a better part of 3 weeks now but suddenly this evening. When I try to load my php webpage(s) it would load one page (or hang) then when I'd go to another page I wrote it would either hang or not load at all (Chrome is continuously "waiting on host"). I've been running Windows Server 2016 64 bit (very clean box here). I haven't had any problems with playing with the built in server until today. We are talking about very SIMPLE hello, world scrips with a couple of html tags here or there. I'm using version 7.2.0 64 bit Development Server. I ever tried x86 for giggles and it demonstrates the same behavior.
my command: php -S localhost:8000 (or any open port) I even used my IP to no avail. Suddenly my development sever just stopped working. I've made no changes to my PC.
I'm not receiving any errors or anything when I try to load my pages. What gives? I've made no changes to the ini file. I can attach if needed. Thank You guys so much!
I figured it out there was a command I was running within one of my php scripts that was causing it to hang! It's working now.
I have a laravel 4 web project that implements a laravel command.
When running in the development homestead vm, it runs to completion (about 40 seconds total time).
However when running it on the production server, it quits with a 'killed' output on the command line.
At first i thought it was the max_execution_time in cli php.ini, so I set it to 0 (for unlimited time).
How can I find out what is killing my command?
I run it on ssh terminal using the standard artisan invokation:
php artisan commandarea:commandname
Does laravel 4 have a command time limit somewhere?
The vps is a Ubuntu 4.10 machine with mysql, nginx and php-fpm
So, firstly, thank you everyone who has pointed me in the right direction regarding PHP and laravel memory usage tracking.
I have answered my own question hoping that it will benefit laravel devs in the future, as my solution was hard to find.
After typing 'dmesg' to show system messages. I found that the php script was being killed by Linux.
So, I added memory logging calls into my script before and after each of the key areas of my script:
Log::Info('Memory now at: ' . memory_get_peak_usage());
Then I ran the script while watching the log output and also the output of the 'top' command.
I found that even though my methods were ending and the variables were going out of scope, the memory was not being freed.
Things that I tried, that DIDNT make any difference in my case:
unset($varname) on variables after I have finished with them - hoping to get GC to kick off
adding gc_enable() at beginning of script and then adding gc_collect_cycle() calls after a significant number of vars are unset.
Disabling mysql transactions - thinking maybe that is memory intensive - it wasnt.
Now, the odd thing was that none of the above made any difference. My script was still using 150mb or ram by time it killed!
The solution that actually worked:
Now this is definitely a laravel specific solution.
But my scripts purpose is basically to parse a large xml feed and then insert thousands of rows into mysql using Elequent ORM.
It turns out that Laravel creates logging information and objects to help you see the query performance.
By turning this off with the following 'magic' call, I got my script down from 150mb to around 20mb!
This is the 'magic;' call:
DB::connection()->disableQueryLog();
I can tell you by the time I found this call, I was grasping at straws ;-(
A process may be killed for several reasons:
Out of Memory
There are two ways to trigger this error: Exceed the amount of memory allocated to PHP script in php.ini, or exceed the available system memory. Check the PHP error log and php.ini file to rule out the first possibility, and use dmesg output to check for the second possibility.
Exceeded the execution time-out limit
In your post you indicate that you disabled the timeout via the max_execution_time setting, but I have included it here for completeness. Be sure that the setting in php.ini is correct and (for those using a web server instead of a CLI script) restart the web server to ensure that the new configuration is active.
An error in the stack
If your script is error-free and not encountering either of the above errors, ensure that your system is running as expected. When using a web server, restart the web server software. Check the error logs for unexpected output, and stop or upgrade related daemons and needed.
Had this issue on a Laravel/Spark project. just wanted to share if others have this issue.
Try a refresh/restart of your dev server if running Vagrant or Ubuntu before more aggressive approaches.
I accidentally ran install of dependency packages on a Vagrant server. I also removed and replaced a mirrored folder repeatedly during install errors. My error was on Laravel/Spark 4.~. I was able to run migrations on other projects; I was getting 'killed' very quickly, 300ms timeframe, on a particular project for nearly all commands. Reading other users, I was dreading trying to find the issue or corruption. In my case, a quick Vagrant reload did the trick. killed issue was resolved.
I'm building a website using the FuelPHP framework, which by default prints the execution time and memory usage at the bottom of the page. Now I just noticed that on my local machine, I have a pretty small memory footprint:
Page rendered in 0.0304s using 0.721mb of memory.
I deployed exactly this site (including a snapshot of the database) to my remote test server and suddenly memory usage increases by a factor of 10:
Page rendered in 0.0963s using 7.099mb of memory.
I cannot explain such a big difference from the details of execution alone, so I think the deviation must be in the environment.
Unfortunately I'm mainly a programmer, not really a server admin, so I don't really know where to start looking. So I'm going to ask a bit of a general question, which will hopefully give me some useful pointers: where should I start looking? The code is exactly the same and as far as I am aware both machines (local laptop and remote server) are fairly standard Apache installations with PHP5. Any answers suggesting specific Apache or PHP settings that might cause this, or specific lines to search for in the logs, are welcome.
I realise this is a pretty general question that might get me some downvotes, any constructive critisism is welcomed instead. Basically, I'm at a loss where to even start looking, at the moment.
Update: I decided to first exclude the framework as the culprit, so I ran the following one-line script on both machines:
Locally I get a value of about 115, while the remote server reports about 600.
Update 2: Just noticed I'm running PHP5.5 locally but server is only at 5.3. Maybe some bug that got fixed later - will upgrade that first.
Thanks for the suggestions guys, I fixed the problem.
As noted in the update to the original post, I realised I was running PHP5.5 locally but server was only at 5.3. After some ppa-magic with apt and some help from other questions on SO I managed to install Apache 2.4 with PHP 5.5.x. Now I actually see
Page rendered in 0.0261s using 0.582mb of memory.
locally and remotely
Page rendered in 2.3184s using 1.238mb of memory.
Assuming that a factor 2 is caused by the server being 64-bit and not my development machine, I can live with the remaining difference.
Use Xdebug to find out what functions are using all your memory.
Most likely it's a bug or design flaw in the framework.
It can be difficult or even impossible to get Xdebug working depending on your server. But sometimes it's pre-installed and simple.
I have a PHP 5.3.22 windows server running PHP in fastCGI. It's a Windows Server 2012 but I have also tried this on a Windows Server 2003 box so it does not seem IIS version specific.
If I have a basic PHP page:
<?php
echo 'test';
?>
Why does this take 1 second to load? This overhead seems to stack with further AJAX requests to PHP so this 1 second seems to be adding up.
Basic HTML pages just containing a word "test" from the same server is near instantaneously.
Surly it can’t just be that it takes servers a second to realise this is a PHP file and to prepare PHP for code execution.
I have tried setting the application pool to have more worker processes and to have it’s start mode as “AlwaysRunning” instead of “OnDemand” but alas this seems to have no impact.
Unfortunately changing the PHP version is not an option at this time (would take too long testing, etc).
If it's a clean start, then you shouldn't be experiencing delays anything like that. Perhaps check if you have any plugins or similar running. Xdebug slows down executions, for example.
The problem is when I open any Magento page in browser, including /admin, it doesn't load properly and keeps loading forever. No files where changed - yesterday it was working, today it stopped working.
Can anyone recommend how to debug it? And what might be the reason for this?
There are no any errors in logs, php works fine, we tried rebooting server.
Thank you.
there wont be any errors unless you have low server resources, or maybe you have some content from external servers that probably down right now. first quick debug - open page in chrome and inspect element, you will see what slows your page. or you can check top, no IO problems, enough RAM, no processes running with >100% CPU?
rebooting server never fixes your problems. check if you have cache enabled.
not much information here to tell you exactly whats going on.
I recently ran into this problem too. My Magneto 2 site (on Ubuntu 16.04) worked fine one day and then would continuously load the next. Cleaning the cache and deleting/rebuilding static files made it work briefly, but it would go back to not loading the pages within a few clicks... even the admin.
My fix happened to be that the disk was full. I didn't realize it until I went in command line and updated composer which kept giving me a disk full error.
I switched to the desktop on Ubuntu and ran a disk analyzer, which pinpointed exactly where all my space was being used.
gksudo baobab
I didn't have gksu installed, so I had to install it first by typing:
sudo apt install gksu
It turns out I had backups that had not been deleted. Large tar files that I no longer needed.
I hope this helps!
Edited to include which OS I am using.