Slow Web access

Posted on 2014-12-03
Medium Priority
Last Modified: 2014-12-10

My client has switched his users from a local server to a remote one located in a data center

They have an in-house PHP web app which is quite simple and essentially text based that runs  on Apache for Windows server 2008 - low bandwidth usage - they use SSL to secure the user access

Ever since switching the users to the remote server they have begun to notice occasional latencies
as if an exchange would suddenly grind to a halt, and a few seconds later, would bounce back into action
(a few seconds can sometimes reach 5)
Apparenty the initial GET connection is being responded to approx 500ms later, while the rest of the exchanges occur at around 150ms

I'll try to get more info, but so far that is all I have
Nothing in the windows event logs
And the Server performance indicators don't show any worrying levels

any ideas ?
Question by:Yann Shukor
LVL 12

Expert Comment

ID: 40478695
please verify memory limits in Apache, low bandwidth requirement do not always mean  that PHP requires low memory to render it
good luck

Expert Comment

by:Ahmed Merghani
ID: 40478818
This issue can be caused at different parts. Initially from the network part, how your client connect to the remote Data Center? Is it a global IP that have been rooted to exact machine at Data Center ? - I faced a similar issue and conclude with that rooting  is the problem-.

Or it can be caused by web server part. The processor or memory - as fryezz said- can be the problem and need to be some tuning.

Or it can be at DB server part if your client are using DB.

While the application was working properly, then - I think- the problem will NOT be from the application.
LVL 36

Expert Comment

ID: 40478858
I'm not a betting man, but in this case, I'd be willing to bet quite a bit of money that the problem is due to code that is accessing a database server either inefficiently or incorrectly.

Unless your in-house app disables compression and takes steps to explicitly start sending output to the user before the entire script is finished (using flush), then PHP will exhibit its normal behavior, which is to finish running the script first and THEN send all the resulting output to the user. This means that all the PHP code has to finish running first (database queries and connections, for example) before the initial GET will come back to the user.

So if your code is connecting to a remote database now (e.g. the database server hasn't moved, but the app has, so it no longer has the advantage of being close to home and having super-fast connection speeds to the server), then any inefficient queries or code will start to show their true colors. For example, some scripts will do a SELECT * query and they'll pull back a lot of extra data that's unnecessary to the script (maybe even some binary blobs). When the app and the database server are in the same network, the transfer of that data is extremely speedy, but when they're remote from each other, it may take a hundred milliseconds (for example) to download the same data now.

Databases are just one common cause, but it's truly more about the network connection. A script could talk to ANY other server, and if the speediness of that exchange changes because of the location change, then it will result in PHP taking longer to render the page.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 25

Expert Comment

ID: 40478863
There are many variables that may contribute to slowness including client's machine, client's isp, hosts' isp, hosts' server, etc.
Check the Server performance. Look in log any suspicious, memory check, configuration files, update the server ..etc.

Here's a site with worldwide tests, at least they claim that:

Uptrends web performance monitoring do; full page monitoring such as http, https, connect, ping, SMTP, POP3, FTP, MySQL, Microsoft SQL, Webservice http, Webservice https, DNS and more. Try it to have a full image about your issue.

Pingdom is also a popular choice to keep an eye on server
LVL 111

Expert Comment

by:Ray Paseur
ID: 40479827
from a local server to a remote one located in a data center...
Is it a shared server, by any chance?  There may be load sharing / balancing issues that give rise to the temporary and transient performance issues.  Might be worth asking the server administrators to see if they can identify anything.

Author Comment

by:Yann Shukor
ID: 40480136
Wow, thank you for all your responses.

Gr8gonzo, I think you are on the right track; I have suggested the use of Flush to my client.
Funnily enough I had already suggested disabling 'output-buffering'

Is there any way that we could monitor this behaviour ?
Possibly without slowing things down any further ?

The thing is we are haven't actually been able to
reproduce this behaviour. It did happen once
during our tests and lasted 15 secs.

As often happens it was the users that signaled
this new phenomenon, which seemingly is more
random than systematic.

LVL 36

Accepted Solution

gr8gonzo earned 2000 total points
ID: 40481266
Unfortunately, flush() is just one piece of the equation. There are a few different components that might be involved in output buffering. Web servers often have it turned on so that they're compressing data before sending it (to save bandwidth and speed up the overall transmission at the expense of some CPU), so even if PHP has it disabled and you're using flush(), you may still have the web server doing it.

Disabling output buffering or compression isn't usually a good fix. Bandwidth is a more precious commodity than CPU, so it's usually a good thing to let the web server do its compression.

The better fix is to identify the parts of the script that are taking up the largest amounts of time. For example, if the script performs 5 queries, see if they all take a minimum amount of time to execute, or if one is much longer than another. A quick way to measure performance of queries (or ANY network calls) is to simply log the output of microtime(true) before and after each query / network call. For example:

$results = mysql_query("your query here..."); 

Open in new window

$start = microtime(true);
$results = mysql_query("your query here..."); $line = __LINE__;
$end = microtime(true);
file_put_contents("query_time.log",basename(__FILE__)."\t".$line . "\t" . ($end-$start) . "\n",FILE_APPEND | LOCK_EX);

Open in new window

That should create a tab-delimited file called "query_time.log" with output like this:
index.php      123      0.005312
index.php      234      0.012911
otherpage.php      456      0.007211

...where the first two fields indicate the file and line of code with the query that was run, and the third field is the number of seconds it took to -fully- run the query (make the request to the database server, wait for the server to finish processing the query, and then download the results into memory). For example, the query on line 234 in file index.php took 0.012911 seconds to fully run. My guess is that your run numbers will be a bit higher than the examples above.

Author Comment

by:Yann Shukor
ID: 40481346
Thanks gr8gonzo, I'll pass it along
I think they developed some javascript routine that runs before and after the script to record in order the time
LVL 36

Expert Comment

ID: 40481355
Javascript runs on the browser / client-side. It won't be able to measure the specific lines of code - only the start/end times of the entire request.

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question