Posts Tagged ‘apc’

The limitations of Hostgator unlimited shared web hosting account

Posted in Wordpress on June 23rd, 2011 by HanaDaddy – Be the first to comment

Recently I was looking to enhance the speed of my baby croc account at the
Hostgator. I have no doubt that the Hostgator is the best hosting service provider with the best customer service. That is true. However, my baby croc account became so slow with the growing additional addon domains. You can host more unlimited domains on a single baby croc account.

Let me talk about what you can do first with the Baby croc shared hosting account.

  • Unlimited disk space : my current disk space usage is about 8 GB
  • Unlimite email account : I do not have many email accounts, because it’s headache to maintain multiples email accounts. I would rather recommend to use Google App service
  • Unlimited bandwith : Current monthly transfer records shows that I used over 16GB
  • You can add unlimited addon domains meaning that you can add additional domain with wordpress to the same account without extra charges.
  • You can maintain DNS services for your domain.
  • CPanel, SSH access

It’s so attractive with unlimited disk space, bandwidth, addon domains, and it’s so cheap! It’s only about 7 dollars per month. What more anybody would want form a hosting service?

The baby croc or shared hostings is basically that you are sharing the server with other people. It is not clear how many people are sharing the server together, but it is clear that there are some limitations on what you can do.

Here are some of the limitations

1. The maximum PHP memory size is 64 M per execution.
64MB memory is still amazing, but you can not allow more than that. When you enable ‘php.ini quick config’ in the CPanel, the PHP will read in the php.ini file in your home directory. You can actually edit the file and set ‘memory_limit’ to more than 64M, but in fact memory limit error will occur if more than 64M is used.

2. The maximum number of simultaneous processes are 25.
This is the biggest problem that I am experiencing. If the simultaneous process goes over 25, the web request will result 500 Internal Server Error. If you’re WordPress site is slow and have many simultaneous visitors, many of them will see the 500 Internal server error. I am having problems with one of my WordPress site which has some plugins utilizing curl functions. When the remote site is unreachable, the curl function is basically waiting for the reply and does not timeout automatically. So this process will idle and eats up available processes slots. And eventually my visitors will soon see 500 error pages when maximum available processes are all used up. You have to login to your CPanel and manually kill the idling processes.

One way to solve is to define the Conneciton timeout setting for curl function.

curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 10); //10 seconds time out

3. Does APC work with Shared Hosting?
For security reason, the suPHP is used. And that is fine, but the real problem is that any kind of PHP opcode cache solution will not work including APC. I have searched everywhere to find the solution to implement APC or any similar solution to speed up the PHP processing, but I found that it is not possible under suPHP. APC or opcode cache solution stores binary opcode data in the memory space to speed up the next processing of the PHP resource. However, under suPHP this is meaningless , because each PHP processes are separate processes and won’t be recognized.

By default the php.ini does not come with apc.so file , but I was actually able to install apc.so file and I succeeded to show APC in the phpinfo() result page. And ran some benchmarking software to compare the speed with and without apc.so library enabled. But basically there was no difference in the processing speed. (If you are interested in trying this yourself, let me know)

4. FastCGI can be activated easily.
FastCGI is well known for enhancing PHP processing speeds by running number of persistent processes to handle the requests all the time. You can activate FastCGI by adding below line into your .htaccess file in the document root directory.

AddHandler fcgid-script .php

However, I do not recommend you to activate this unless you are on the VPS or dedicated server. On the shared hosting account, you can have only upto maximum 25 processes. With FastCGI enabled, those FastCGI php processes will take available slots and you have much less simultaneous process slots. Also your website eventually becomes unstable and you would soon see 500 Internal Server Error message.

So I have spent some time to find a way to speed up my WordPress sites , but all the well known methods were all failed.

However, the best method for me was to use ‘W3 Total Cache’ plugin . It is little bit confusing when you first try to set the settings with all the options. But I only recommend to use Page Cache. Database cache will create so may files in the disk which will increase the number of inodes. (There is limit on the number of inodes you can create under Hostgator Shared account) But the result is amazing!

If you know a good tip on speeding up PHP process under Shared hosting account, let me know!

Thank you for visiting wpmarking.org.

Faster PHP with Fastdomain Shared Hosting Account with PHP APC extension

Posted in Marketing Tools on April 20th, 2010 by HanaDaddy – Be the first to comment

Now I decided to share my personal know how on how to activate PHP APC extension under FastDomain shared Hosting account. You won’t find this information anywhere because I found it myself by trial and error.

FastDomain’s shared hosting account is OK and this is my second year with FastDomain. About a year ago, I had a little project to work with Magento. I had to deploy an ecommerce site and I reviewed various free shopping cart solutions. And my final decision was Magento. It’s an open source software and backed by large and active community. It is pretty flexible, powerful and free.

However, the catch was that the Magento requires at least 32 M for the memory_limit settings of php.ini. (Now the minimum memory requirement is unbelievable 256M) But 48M or 64M was recommended. Also it needs more CPU power because it is based on Zend Framwork. Zend Framework is very popular framework from the Zend, maker of PHP. But it requires much more memory and CPU power than conventional PHP scripts.

But the FastDomain’s default PHP memory_limit was 32M and the Magento’s initial speed under FastDomains’s shared account was somewhat slow and disappointing. However, for me, there was no additional budget for a dedicated server or even a Virtual Private Server which costs at least $35 per month.

So I decided to look for the ways to optimize the Magento. Many discussion forum articles were discussing about APC (Alternative PHP Cache) PHP extension. This extension is basically to boost the performance of software applications written using the PHP. Most PHP accelerators work by caching the compiled bytecode of PHP scripts to avoid the overhead of parsing and compiling source code on each request. And it can improve the speed by 1~3 times faster. I was really happy becauseI thought that I finally found the right solution.

But then I realized that FastDomains’s PHP configuration does not support APC extension by default. At this point, I was really tired of Magento but decided to give one more chance and searched Google and tried everything that I could with CPanel.

And I finally found the way to increase the memory limit over default 32M and how to deploy APC extension under FastDomain. So here they are.

Requirements:

  • You need to have SSH terminal access to your account. By default SSH access is not enabled, but you can easily get the access by applying for it. (Try ‘SSL/Shell access’ icon in CPanel)
  • If this is your first time with SSH, you should download PuTTY SSH terminal program.

  • Some knowledge of Linux console command is recommended. (For example, how to navigate between folders , list directories, move files, etc) But you can use FTP program to do the same tasks.

Step 1

From the CPanel, click on the ‘PHP Config’ icon.

image

Step 2

From the page, you can have customized php.ini in your ~/public_html folder. First , you will need to decide how to load customized php.ini file. If you want to create one php.ini file and use it globally through out the subdirectories and add domains folders, select “PHP5(Sing php.ini)” option. If you want to have different settings in php.ini for different addon domains, select “PHP5”. If you select ‘PHP5’, you will need to save php.ini in each subdirectories that you want to apply customized php.ini settings.

image

Second, click on the ‘INSTALL PHP.INI MASTER FILE’ button to save default php.ini.default file into your ~/public_html folder. You can edit this file according to your needs and renamed it to php.ini later.

Also , at this point, I recommend you to create test.php and add below snippet to check the APC extension is installed and enabled successfully at a later time. This file can be saved anywhere but let’s save it right in the ~/public_html, so you can access it by typing ‘http://yourdomain.com/test.php

<?php
phpinfo();
?>;

Why don’t you test it now? You will see a webpage similar to below image. If you try to find keyword “APC” in the web browser, you won’t be able to find it since we haven’t enable it yet.image

Also note that the default memory size is 32M. image

Step 3

Now rename the ~/public_html/php.ini.default file to ~/public_html/php.ini. Then you can use ‘vi’ editor or download to your PC using FTP to edit it.

First, we would like to increase the memory_limit. Search the ‘memory_limit’ keyword and edit it to your preferred amount of memory. I used 128M just for this demo. For your information, I never used large number for the memory. I used less than 64M just in case.

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;
max_execution_time = 30     ; Maximum execution time of each script, in seconds
max_input_time = 60     ; Maximum amount of time each script may spend parsing request data
memory_limit = 128M      ; Maximum amount of memory a script may consume (32MB)

After editing the file, you can try to reload the test.php page to see if the update is reflected properly.

image

Ok, this was easy.

Step 4

Now, we are ready to deploy APC extension. Fortunately, FastDomain shared hosting account provides C compiler. You will need to download APC source code and compile apc.so and define it in the custom php.ini file. The compilation process is not that difficult.

Download http://pecl.php.net/get/APC-3.1.2.tgz and upload into your account path ~/public_html

Now login to your FastDomain SSH account and run below commands.

#cd public_html
#gunzip APC-3.1.2.tgz ; tar xf APC-3.1.2.tar
#cd APC-3.1.2
#/usr/bin/phpize
#./configure --enable-apc --enable-apc-mmap  --with-php-config=/usr/bin/php-config
#make
#cp modules/apc.so ~/public_html

After this, you will have apc.so file in the ~/public_html folder. Now you are almost ready.

More references:

Step 5

Open php.ini to edit file again. At the end of the file add below lines. Note that “yourid” in the extension path should be your login id.

[apc]
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64
apc.max_file_size = 10M
apc.stat=1
 
extension=../../../../../../home/yourid/public_html/apc.so

Once you save the file, try the test.php file to see if APC is loaded successfully. If you search for the keyword “APC”, you will be able to find one. Wonderful!

image

If you can’t find “APC”, check out the ~/public_html/error_log. You will be able to find some clues why it didn’t work.

Remember, APC extension helps not only Magento but all PHP applications. Once the setup is completed, it affect all the addon domains too (under single php.ini option). Enjoy the benefits of APC today! I mean if you are using FastDomain shared hosting service.

One thing to note is that you will need to compile apc.so everytime the PHP is upgraded in your FastDomain server. When the PHP version is upgraded, your old apc.so won’t work unless you compile it again.

Thank you for reading and please leave any comment.