Solved

Advice on PHP 5 Accelerators and Zend Debugger

Posted on 2008-06-24
9
970 Views
Last Modified: 2009-04-08
The time has come to optimise, the boss wants the application to be more 'Snappy'
The application is heavily OOP with around 20,000 lines of code.
One class per file etc.

Current environment.
Development / test machine.
WindowsXP, Apache 2.0, PHP 5.2, MySQL 5, Zend Studio 5.5

Production Environment.
Suse Linux 10, Apache 2.0, PHP 5.2, MySQL 5

A couple of questions which opcode cache is better APC or Xcache ?
Want to have something which gives us lots of tuning statistics.
So I know where to focus my efforts.

Another burning question is Op code caches and Zend studio remote debugger.
The debugger is damn handy and I don't want to loose it!
The remote debugging is only required on the development machine.

Do I need to run 2 apaches on my development machine bound to different TCP ports.
With 2 different php.ini files.
One with Zend Remote debug.
And one with the Op code cache.


0
Comment
Question by:Matthew_Way
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 4

Expert Comment

by:snrudda
ID: 21864631
First thing to think of is to use Zend products both for development/debug and for cache. Even Zend Optimizer should do the trick. Caches are good nowadays so you won't notice the difference between.

But if you think about speed up your application maybe it would be better to make some application level-cache so you: codC won't redo exact the same things every time. As you know what your code should do you cat tell where the cache should be placed.

You may also consider to use different web server (say nginx or lighthttpd to serve at least static content of your site (and try to convert dynamic pages into static ones, say by rendering news page into html once a minute instead of generate it on the fly every time, and serve that static page with nginx).
0
 

Author Comment

by:Matthew_Way
ID: 21865507
I read that zend optimizer wasn't an opcode cache.
0
 
LVL 4

Expert Comment

by:snrudda
ID: 21865829
Yes you're right but as of my experience I faced segmentation faults with both APC and XCache, but it was a bit ago so now these caches may be more stable. This was the reason I choose Zend Optimizer, as my script was too heavy and Zend was good on it. Lucky me and no seg. faults. But I'd say my setup was some LAN site so I could afford not to use op-cache.

I'd vote for XCache just because of its developer, who also behind Lighthttpd. I'd also try to test your code both under XCache and APC, and choose which one gives better results on _your_ code. But of course kind of watchdog should be set up to check if cache goes bad. You might tail Apache logs for 'exit signal Segmentation fault' lines and reboot server at that time.
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 

Author Comment

by:Matthew_Way
ID: 21870839
Well the application is on the internet, and the server is doing other work as well.
So I need to look at ways of reducing CPU load.
I can't generate pages as static pages because it's a secure / members only type situation.
And at the very least the authorisation and tracking parts of the code need to run for each request.

And I figure in the future if we start to use AJAX then the problem of CPU usage on the server will be even worse.

Any ideas with Xcache and Zend remote debugger ?
0
 
LVL 4

Expert Comment

by:snrudda
ID: 21882324
First, there are a lot of content that really static (images, CSS). And if you think about you can rewrite some code so it will be built of some static (generic) parts. You can even make index.html static instead of dynamic index.php, but in the beginning just include javascript (which will be generated by script) that will contain say username and some per-user settings, and javascript on the index.html page will render personalized page just for the user.

You can even go even further and create per-user dirs under your webroot named after usernames. Put per-user files there and limit access (via HTTP auth) there .httaccess so only user with given username will have access to his personal dir. So yo3 will be able to include per-user info the page by referring to content of such a dir, but only the user will see the content that should be seen only by him. Tricky but saves a lot of web server CPU. Static files may be serverd by lightweight web server and per-user files may be created by backend asynchronously when some user data is changed.

As for opcache and debug I'd set up production server with opcache only and test server only with debug support. You can always turn debug off and turn opcache on on test server but generally there is no point in caching on test server where there are only a few users. Don't even bother with opcache + debug, this is what I'd say.

You can also investigate way to use not Apache but ngnix (http://nginx.net/ or wiki at http://wiki.codemongers.com/Main) to serve php content too. This server handles high load very well, but it uses Fast-CGI (only a fewPHP  projects won't support that). Quick search at Google given a lot of info on that. Ngnix cookbook example also exists:

http://wiki.codemongers.com/NginxFcgiExample
0
 
LVL 4

Accepted Solution

by:
snrudda earned 500 total points
ID: 21882345
General rule of thumb for heavy coded sites is "Try to execute as much heavy code in the background while output pages by lightweight server that won't almost-freeze the system on each request".

Maybe you should also think on redesigning the setup and even on rewriting the code so it can be scaled by adding extra servers. Say put heavy-loaded SQL on one server and we server on another...
0
 

Author Comment

by:Matthew_Way
ID: 21883052
Yeah, I think the double edge sword is the heavy use of PHP5 OOP

It does actually run fast enough the problem seems to be actually loading the scripts rather than executing them.
Will also be caching more page components, which presents its own challenge as the application is also multilingual.
All javascript / css / images are already offloaded into a static area.

Leaning towards Xcache because of the amount of statistics plus we can use runkit with it.

Already using Apache / FastCGI not sure if Xcache will share opcode cache across FastCGI threads.

Reason I want to use opcode cache on the development machine is so that I can tweak the application to make it more cacheable.
But don't want to loose remote debug, it's so useful.
Will just have to switch it on  and off or run 2 Apache's talking to the same files just different php.ini's

My other problem I have with the Zend Studio 5.5 is that it has bad UTF8 support.
But I'm trying to keep separation from code and templates.
So using smarty which is great apart from the over head.
Like the principle but may replace it with something a little more light weight.
 
0
 

Author Comment

by:Matthew_Way
ID: 21893378
Okay making progress.
Have now got XCache installed seems to run well.
Figured my application wouldn't be very cacheable as I use __autoload() and lots of conditional includes.
But Xcache seems to take it all in it's stride.
Not sure what the performance gain is need to change the application so I can run apache bench against it.

Xcache wont seem to work with Zend Optimizer or Zend Debugger but was expecting that!
0
 

Expert Comment

by:percuno
ID: 24100313
Because of the sheer amount of code and the fact that you have stated the loading of scripts seems to take longer than execution, I would suggest that you consider a few things:

1) Are you using a disk subsystem that is bottlenecking your site? A lot of people seem to have forgotten that hard disks are electromechanical devices and as such, are extremely slow relative to the rest of the computer. This is the reason servers have for some time been equipped with expensive SCSI and RAID controllers. A lot of new servers have "cheaped out" and gone with something called "fakeraid" which uses SATA hard drives to make software or hybrid hardware-software "RAID" subsystems which are not up to par with a real SCSI or SAS RAID device.

Anything less than a hardware based true RAID system with 15,000 rpm SCSI or SAS drives is going to slow your system down. In fact, even that will slow it down, just not as much.

Make sure your system drives are on a different RAID from your data drives, as well.

2) Are you falling for the "Mighty CPU" sales tactic? A lot of hardware providers and even VARs are pushing multiple Quad-core CPUs on people who don't realise that the CPU is far from the most taxed component of most servers unless you are engaged in heavy-duty scientific calculations or hypercube data mining. I have an older single-socket dual-core CPU in one of my most heavily used LAMP servers and the CPU in this machine basically sits idle all the time. It rarely goes over 1% utilization and almost never over 30%.

3) How good is your memory? Is it fast enough? Do you have enough of it? I wouldn't build a server with less than 4GB now, even knowing that it isn't all going to be used without a 64-bit OS or one compiled for PAE. RAM is cheap, even the DDR3 kind (I don't think you can get that for a server anyway but I haven't really checked) is relatively cheap for what you get out of it.

4) Are you using your CPU and RAM effectively? If you have a 64-bit CPU, and it's highly unlikely that you don't, and 4GB or more of RAM, you might gain something from using a 64-bit operating system, or alternately using a 32-bit OS that has been compiled for Intel's PAE extensions which allow a machine to fully utilize 4GB or more of RAM, up to even 64GB. Beyond 64GB you will have to go with a full 64-bit OS.

There are also many other things you can do to make your server more responsive, including MySQL configurations (query caching, etc.) and so on. System optimization is a broad subject and goes far beyond simply installing a PHP accelerator, but you get out of it what you put into it in terms of time and money.

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

724 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