Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, September 30, 2009

Flickr and PHP

Check out this SlideShare Presentation:

Building Scalable php applications

Check out this SlideShare Presentation:

Saturday, September 26, 2009

Use Amazon S3

Amazon is great hosted storage solution, that lets you store unlimited number of files for the pennies on the dollar.

We used Amazon S3 for our clients to maintained media files because we are using load balancing server. It is the best solution to store media files on load balancing servers.

As the part of the post i will demonstrated the easiest way to put Amazon S3 to use in minutes.

=====================
First Step: Sing up for Amazon S3
=====================
if you haven't signed up for an Amazon S3 account, Signup here

Save your Amazon S3 access key and secret key, those keys look like this
Example:
Access Key: 0BEZAVZXSW2JMREDVZW2
Secret Key: IR41Aa938YQgjVlUcajs6E4tq5O8sHMwerB4C9Be0

========================
Second Step: Install S3 binary library
========================
While S3 offers API libraries for all popular programming languages.
You PHP S3 library also.

Tuesday, September 22, 2009

Opcode Caching

The code which you wright in PHP the PHP compiler convert that code in OPCODE.
The best you can also add OPCODE caching in your PHP applications.
The Few opcode caching listed bellow.
1. eaccelerator [eaccelerator]
2. XCache [http://xcache.lighttpd.net/]
3. APC [http://in3.php.net/apc/]

Using this tools you can cache PHP Opcode.
The Opcode caching improves your application performance.

Monday, September 21, 2009

Professional PHP: an open-source alternative for enterprise development [Kortrijk]

Check out this SlideShare Presentation:

Memcached

If your not using memcached means your site don't have high traffic but i started memcache for 2 reasons.
1. Query Optimizations
2. On server load balancing store sessions in memcache

Memcached Link: http://in.php.net/memcache

Memcache stores the cache in memory but its not very relabel if crash the chances of data will lost.So when i store sessions in memcache also maintained sessions in database if suppose memcache server crash next time data get from database.

But for query optimizations memcache is best.
You can cached quires even php class objects.
In our framework we have model class so what i do i am adding the model class object in memcached.
The data which i am caching the memcache server which is not frequently changes like site categories, country, state.

Facebook also using memcache and they have also hack the memcache system for relability.

Sunday, September 20, 2009

flickr's architecture & php

Check out this SlideShare Presentation it will help us more PHP optimizations

Saturday, September 19, 2009

Avoid require_once and include_once

I have working on my own framework and in that framework contains many library files.
In many library files we are using require_onces.
Now we little optimized in this also using require because require_once is more heavy then require.
Try to avoid require_once or inculde_once.
May be you doing this because of lazy inclusion.

More foreach optimization

Suppose you key value array and your using foreach i have done one more optimization.
I am using while loop.
$array = array('first'=>'max','second'=>'pain');
foreach($array $key=>$value)
{
print 'Key: ' . $key . ' Value: ' . $value ;
}

=====Optimized Code=====
while(list($key,$value)=each($array))
{
print 'Key: ' . $key . ' Value: ' . $value ;
}
=====Optimized Code=====
The while loop runs more faster then foreach.

Thursday, September 17, 2009

Start with simple foreach optimization

We used most of the time PHP array to save code information, objects, list.
Most of the time we used foreach loop to read array values but i want share one simple optimization in that foreach.
I wrote bigger script for fixing bugs in my applications.
My applications contains many databas connections and many rows and i am using the objects so most of the time my script was failing because of the memory execution issue.
The simple optimization i had done with PHP foreach loop.
Previously i was using like this:
$array_of_objects = $object->getList();// contains may records more then 10000.
if(count($array_of_objects)>0)
{
foreach($array_of_objects as $key=>$object)
{
// the object processing
}
}

======= Optimized code=======
$array_of_objects = $object->getList();// contains may records more then 10000.
$size_of_objects = sizeof($array_of_objects);
if($size_of_objects>0)
{
for(i=0;i<$size_of_objects;$i++)
{
$object =&
$array_of_objects[$i];
}
}
======= Optimized code=======

=======Why i used For=======
basically foreach loop copying the array of objects but in for loop i am using array of objects using
as reference it will save memory.
=======Why i used For=======