Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1155
  • Last Modified:

Linux PHP web server images display very slow

Hi,

I have problems with my Linux WEB server.
Among others, I have over 10 Microsoft web servers, some of them on ESX 4.1 platform, everything running smooth.

But on this particular Linux server I have weird issue:
- after REBOOT web server is blazing fast...really
- but after A COUPLE OF DAYS, server displays images really extremely SLOW...
Images draw line by line and it takes FEW MINUTES for image to display, regardless of image size; even thumbnails of few kB in size take 30-60 seconds to display on screen.

Now, what I have done already:
- tested from different locations, different OS, different browsers...there is always same problem
- setup new domain, new site....still the same problem
- tried with different JPEG compressions...no avail also
- copied images and whole web site to WINDOWS server...and it's normal there
- converted pages from PHP to flat HTML...woila, images display super fast
- ok, I googled for similar problem, and DISABLED persistent connections in APACHE config....but after few days all the same problem again

So conclusion is:
1.) Images display slow only via PHP processor.
2.) Problem becomes worse every day...until I reboot, then game start over

Ubuntu 10.4 LTS, patched and updated
Apache 2.2
PHP 5.3.4

Server is 64-bit, 16 GB RAM, RAID 10 SAS 15k disks, Dual Quad-core XEON
Located in datacenter, multiple backbone

Any idea what else (beside disabling persistent connections) should I try?

0
Andrej Pirman
Asked:
Andrej Pirman
  • 10
  • 5
  • 3
  • +1
2 Solutions
 
Scott MadeiraCommented:
If it is fast when you reboot and then gets slow your problem is probably related to resources being exhausted.  I would start by looking at CPU utilization on the server, processes that are running, memory utilization ( maybe something has a memory leak and you are paging like crazy.

It is something specific to that server (as you discovered) and is probably more related to the OS.

Another thing to check would be the php.ini files to see if timeout and memory values are the same on that server as they are on the other (windows) servers you are running.  Perhaps PHP is consuming significantly more resources or not releasing resources the same way between servers.
0
 
Andrej PirmanAuthor Commented:
Hi,
only your 3rd suggestion makes sense in my case. CPU is not utilized, nor it is OS-related, because even when PHP powered images are slow, plain old HTML-powered images are blazing fast.

So it must be something related to APACHE and PHP.
But what?

I manage PHP powered servers from the very begining of PHP project, bu I never faced this problem before.
PHP.INI is either default, either edited, but in both cases images get slow after a day or two.

Seems like some kind of BUFFER or somehing else gets accumulated over time....maybe too many handles, too many *I-don't-know-what in memory...
Seeking for tip how to find out.
0
 
crazedsanityCommented:
Is the PHP page in question doing something database-oriented?  If the image is getting passed through a PHP script (e.g. "http://site.com/php-bin/myscript.php/path/to/file.jpg" is actually a PHP script that outputs the contents of a specific file after doing some database stuff), it could be something happening before the image is processed.

Narrowing the problem would be helpful:::

Is the image getting passed through a PHP script somehow?

Try loading the image itself in the browser, outside of the PHP script.

How many Apache processes are running when the problem occurs?  Try stopping Apache, making sure ALL apache processes are done, then starting it back up... is it fast again?

Are the files that are downloaded getting bloated somehow (much larger than normal)?

When the problem occurs, edit the problematic script directly.  Put in "exit" statements through the file systematically, so you can potentially narrow it down to a single line:
exit(__FILE__ .": ". __LINE__);

Open in new window

0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
crazedsanityCommented:
I ran into a problem with my website being sluggish a while back.  I was hell-bent on the idea that somehow my database was causing the problems.

After a while, I figured out how to turn on XDEBUG on the server so it would give me information that was able to be parsed by a program "KCacheGrind" (that's the linux program... not sure what the Windows version is).

Anyway, through all that, I eventually found out that the culprit was PHP itself.  I was using the magic __autoload() method, which helped to dynamically load libraries... it scanned the filesystem something like 1500 times per library, so the slowness of the server's hard drives really came into play:  Cache grind output
Hope that helps.
0
 
Scott MadeiraCommented:
This link is for some linux commands that will help you see what your system is doing.  I'd look at cpu, memory, disk, processes and network info when the system is running well and then when it is going slowly.

Hopefully something is out of whack and will give you the place to start looking.
0
 
Scott MadeiraCommented:
0
 
kelvinwkwCommented:
Try update your PHP to a latest version.
0
 
Andrej PirmanAuthor Commented:
Hi everybody, step by step:

- PHP updated to 5.3.2, build date Oct. 15 2011
  Nothing changed...randomly images load slow

- CPU, disk, networking...well, if image alone or within HTML page loads FAST, and just inside PHP page load SLOW, it means CPU, disk, networking is NOT the problem. Should not be.

- Here is a test:
http://secureit.si/test.php    <--- randomly problematic
http://secureit.si/test.html
But it is random - sometimes both load FAST, but sometimes just PHP IS SLOW.

- By SLOW LOADING image I mean image starts displaying, but renders slowly line-by-line and it takes unreasonably too much time.

- Number of Apache processes?
  I haven't catch the right moment to find out.

- Is file bigger?
  Well... if I look in web page properties, it is G-ZIP-ed, but I was not paying attention on file size.

It is problematic since issue arises randomly, and also local browser cache jumps-in, so I have to test on-the-go, when I am at some customer or somewhere else.
0
 
kelvinwkwCommented:
I might be wrong but your image size is about 400k in size. You need to reduce the file size.

I tried both on private browsing mode each and it appears both loaded about the same time.
Once the image cached by the browser, it loads faster.
0
 
Andrej PirmanAuthor Commented:
Yes, image is 400 kB, but, well, how long would it take on my 100 Mbps line?
100 Mbps / 8bit = 12,5 MB/s
So on 100 Mbps line image would load in 1/30 of the second, it is 0,034 sec
On 10 Mbps line 0,3 sec.

Ok, but let's test speed on this server....just a moment to install speedtest....
http://secureit.si/speedtest

Nope, it's not speed issue, server has full speed (from my home 98 Mbps download and 97 Mbps upload)


Oh...what I noticed:
My PHP test page loaded SLOW after I cleared browser cache and waited 1 day. Then closed browser, cleared cache, rerun PHP test...and woups....it is FAST.
So I assume image gets somehow cached on SERVER side...or web page cached on server.
Which means, it is slow only FIRST TIME, then server delivers it fast until it throws it out of internal cache.

Cuould it be somethong like that?
0
 
crazedsanityCommented:
If you want to eliminate caching, as a possible issue, have the PHP script output the current time at the top of the page.  Also, to keep the image from being cached, a good trick is to add an argument to it with a timestamp.  So the image tag would look something like:
<img src="http://secureit.si/wp-content/uploads/ASF_with_Exchange.jpg?_=1319834120">

Open in new window


The browser believes it is a different file, so it has to be downloaded, thereby eliminating caching as a problem.

It looks like a fairly simple PHP page, could you provide us with source?  There could be something that a "fresh pair of eyes" might spot.
0
 
Andrej PirmanAuthor Commented:
Well, this test.php file is plain simple. I added your suggestions for not-caching images, and also simple processing counter:
<?php
session_cache_limiter( 'nocache' );
$time_start = microtime(true);

echo 'PHP test<br>';
echo '<img src="http://secureit.si/wp-content/uploads/ASF_with_Exchange.jpg?_'.$time_start.'">';

$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br />Script execution time ".number_format($time,6)." seconds";
?>

Open in new window

0
 
Andrej PirmanAuthor Commented:
I also changed the script to actually create new file each time page is loaded, so it is actually DIFFERENT FILE on each load....but once I get it running, it is very fast:
http://secureit.si/test.php
<?php
// session_cache_limiter( 'nocache' );
$time_start = microtime(true);
echo 'PHP test<br>';

$oldimage="./wp-content/uploads/ASF_with_Exchange.jpg";
$newimage="./wp-content/uploads/test/".md5($time_start).".jpg";

if (!copy($oldimage, $newimage)) {
    echo "Failed to copy ".$oldimage." to ".$newimage."<br>";
} else {
	echo "Image copy OK.<br>";
	echo '<img src="'.$newimage.'?_'.$time_start.'">';
}
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "<br />Script execution time ".number_format($time,6)." seconds";
?>

Open in new window

0
 
Andrej PirmanAuthor Commented:
There must be something with APACHE or LINUX wrong on server. I run simple web stress test which hit the barrier at:
8 page requests per second
which was after 4600 hits

Seems like some buffer fills up and produces errors (see graph below):
 web-stress-run1.PNG
0
 
crazedsanityCommented:
Maybe the problem is something with memory, maybe the server is caching at that time or something.  Since you can (assumedly) reproduce the problem at will, running top might be helpful, along with iostat or vmstat... one of them will probably show something bad happening in memory.

Maybe apache is keeping too many children alive, or... something.  You can try removing unused mods from apache as well; look in the /etc/apache2/mods-enabled/ folder to see what is enabled, a2dismod {name} will remove it (and you'll need to do a restart on apache).
0
 
crazedsanityCommented:
It may be helpful for us to know something about the server's CPU, RAM, and how big it's swap is, if the iostat/vmstat/top thing doesn't give anything useful.  Just a thought.

Is this server a VM, or physical machine?
0
 
Andrej PirmanAuthor Commented:
It is a VM on ESX 4.1
64-bit, 16 GB RAM (out of 64 total), RAID 10 SAS 15k disks, 4 CPU cores out of Dual Quad-core XEON
Located in datacenter, multiple backbone

Other VM's on this same host do not have any problems (there are total of 3 web servers on this particular ESX host)
0
 
Andrej PirmanAuthor Commented:
It was all fine now for 1 month...but hey, problem came back!
TOP shows nothing - none of the process take any CPU, it's almost idling all the time.
0
 
kelvinwkwCommented:
Try to look for patches for the ESX Host.
0
 
Andrej PirmanAuthor Commented:
I've migrated this VM instalation to single server...but still the same issue. :(
Most of time it works, but from time to time it stucks, hicups for some time...then it's fine again.

If no more suggestions are given, I'll close this question.
0
 
Andrej PirmanAuthor Commented:
My apologee for waiting few months to close the question, but the problem was not resolved using any suggested method, but simply vanished thru time. I mean, after numerous updates, patching, upgrading everything, even disks and RAM and CPU, so I actually did not focus on the problem to see when it disappeared.
Tried to split the point for excellent participation, thanx!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 5
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now