* You are viewing Posts Tagged ‘PHP’

Tips to Improve Drupal Websites Performance

Drupal wesbite?? Want to improve Performance?? Here are the few tips:

1. Always keep the Drupal core and the contributed modules used in your application updated. Many a times, the updates include performance improvement.

2. Disable the statistics module which writes to database on every hit. You may not need this module if you are using Google Analytics.

3. Consider disabling modules like Administration Menu, Database Logging or Overlay which take a heavy load on performance. If your site does not require per field permissions, you can also consider disabling CCK Content Permissions module.

4. If you are using Views module, use caching of … Continue Reading

Different PHP Loops

Hey Folks,

Now its time to get aware with different php loops in php. Followin is the information about do..while loop, while loop, for loop and foreach.

Basic Loop Concept

You may think how loop is useful and why it is needed ? Here is simple way of explanation. If you want to add 10 numbers, you can do it using arithmetic operator and variables.
<?php
$total = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
?>

Now if you want to add 100 numbers, 1000 numbers and even more. Will you write such a long … Continue Reading

PHP MySql fetch_assoc Vs fetch_array Vs fetch_object performance difference

In this post we will see how these 3 main MySql data fetching methods in PHP performance.

In almost all php-mysql programming, you will need to fetch data from database to populate your applications with data.

There are 3 most popular methods of getting more than one data set when fetched.

mysql_fetch_assoc() : This function fetch an associative array of data.
mysql_fetch_array() : This function returns a combination array of associative elements as well as data with numerical index.
mysql_fetch_object() : This function returns an object with properties that correspond to the fetched row.

Each data set contains a unique id element, int & a … Continue Reading

Get months from two date range in PHP

Here is the code you are looking for:

function get_months($date1, $date2) {
$time1 = strtotime($date1);
$time2 = strtotime($date2);
$my = date(‘n-Y’, $time2);
$mesi = array(‘Jan’,’Feb’,’Mar’,’Apr’,’May’,’Jun’,’Jul’,’Aug’,’Sep’,’Oct’,’Nov’,’Dec’);

//$months = array(date(‘F’, $time1));
$months = array();
$f = ”;

while($time1 < $time2) { if(date('n-Y', $time1) != $f) { ... Continue Reading

How to download remote file with CURL using PHP

You can read the response and store it to the disk.
Use below code to get your job done.
<?php
$url = ‘http://yourdomain.com/path/filename.ext';
$file_path = ‘/path/foldername/filename.ext';

$fp = fopen($path, ‘w’);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);

$response = curl_exec($ch);
?>
That’s all. Now you can download file hassle free.

Sending Emails from Amazon SES using PHP

Here the PHP code to send emails from Amazon SES.
require_once(‘ses.php’);

$objSes = new SimpleEmailService(‘accessKey’, ‘secretKey’);

$send = new SimpleEmailServiceMessage();
$send->addTo(‘xxxx@example.com’);
$send->setFrom(‘Name <yourmail@example.com>’);
$send->setSubject(‘Amazon SES email!’);
$send->setMessageFromString(‘Awesome, you got the email.’);
$objSes->sendEmail($send);
You can get ses.php from
http://www.orderingdisorder.com/aws/ses/
!! Happy Coding !!

Immediate availability of PHP

The PHP development team announces the immediate availability of PHP
5.4.11 and PHP 5.3.21. These releases fix about 10 bugs. All users of
PHP are encouraged to upgrade to PHP 5.4. PHP 5.3.20 is recommended
for those wishing to remain on the 5.3 series.

The full list of changes are recorded in the ChangeLog on
http://www.php.net/ChangeLog-5.php

For source downloads of PHP 5.4.11 and PHP 5.3.21 please visit our
downloads page at http://www.php.net/downloads.php

Windows binaries can be found on http://windows.php.net/download/

PHP Array Function: array_change_key_case

The array_change_key_case function allows you to manipulate the textual data in an array by transforming it into uppercase or lowercase.

Syntax:
array_change_key_case(array, CASE_LOWER or CASE_UPPER)
The array is the name of the array whose values you wish to convert to upper or lowercase.
The parameter CASE_LOWER or CASE_UPPER is used to determine whether or not you are going to convert the values in the array to upper or lower case.

Example:
<?php
$arrLevel = array (“a” => “Programmer”, “b” => “Analyst”, “c” => “Administrator”);
print_r(array_change_key_case($arrLevel, CASE_LOWER));
?>
The above code takes the values in $test and converts them to lowercase.
Converting your array values to uppercase is as simple as changing … Continue Reading

Tips for Coding Cleaner PHP

PHP is lovely, though if you ever work with other people having good code is important. Here are some tips to improve your code.

Comment & Document
It’s really important that people understand why you are doing certain things in certain ways. Adding a quick comment above sections of code should be adequate, but documenting classes and functions is fantastic.

Give Variables, Functions and Classes Meaningful names
Nothing is worse than trying to figure out what a function does. Give everything a name that if someone else looked at it, they could figure out what it does.
Example:
function fetch_user_info();
Never Delete – Comment out
This one is … Continue Reading

Speeding Up Your PHP Web Site

Google already announced that the speed of a web site is now used as a factor in determining its search rank. This is great news for the skillful PHP developer, since it allows you to gain an advantage over those not as dedicated to their art.

Following techniques you can easily adapt to your own web sites and web applications.

When I set out to speed up this web site, I used the Page Speed and YSlow plug-ins for Firebug as a basis for determing what to do. As a result, the key things that were looked at were as follows:

– Using … Continue Reading