User Agent Parsing with PHP

Tobie Langel’s ua-parser, a great library which provides simple UA parsing in PHP, JavaScript and Python.

<?php require_once 'uaparser.php';

$parser = new UAParser();
$result = $parser->parse($ua);

echo '<pre>';


Mistserver Manager Login

Find more libraries here...

Upgrade PHP & MySQL on Plesk 10

1. Stop Running Apache & MySQL Server
# /etc/init.d/mysqld stop
# /etc/init.d/httpd stop

2. Set up the atomic channel
# wget -q -O – | sh

3. Upgrade to PHP 5.3.x on plesk 10
# yum upgrade

Now I can install “uploadprogress” extension easily

pecl/uploadprogress requires PHP (version >= 5.2.0), installed version is 5.1.3
No valid packages found
install failed

# pecl install uploadprogress

Then add in /etc/php.ini

PHP Bulk Emailer

If you send email to 5,000 people using standard PHP tools, your ISPs might be blocked in seconds.

I think you already read below articles…

Amazon Simple Notification Service Command Lines

Theory About Bulk Emails

Emails are not working on server?

Amazon SES – Emails In Cloud

Open source – Port25

Linux Mail Servers

Email’s Major Sections

Header – From, To, Subject, Date, Message-Id
Body – HTML / Text

Server must have …

* Dedicated public static IP address
* Reverse DNS record for IP address
* Contact info in WHOIS record
* Mailbox Tracker
* SPF Records
* Signed message using DKIM
* VERP – Variable envelope return path
* Automatic Bounce Handling
* Email Scheduler
* Email Subscribe / Unsubscribe
* Keep the IPs white-listed

Limit on servers

500/per hour on the Shared servers is the limit.

Other References

PHP PEAR File Download Package


The PEAR package contains:
* PEAR installer, for creating, distributing and installing packages
* PEAR_Exception PHP5 error handling mechanism
* PEAR_ErrorStack advanced error handling mechanism
* PEAR_Error error handling mechanism
* OS_Guess class for retrieving info about the OS where PHP is running on
* System class for quick handling of common operations with files and directories
* PEAR base class

Features in a nutshell:
* full support for channels
* pre-download dependency validation
* new package.xml 2.0 format allows tremendous flexibility while maintaining BC
* support for optional dependency groups and limited support for sub-packaging
* robust dependency support
* full dependency validation on uninstall
* remote install for hosts with only ftp access
* full support for mirroring
* support for bundling several packages into a single tarball
* support for static dependencies on a url-based package
* support for custom file roles and installation tasks

Traditional Code


$path = "svnlabs.csv";



$size = filesize($path);

header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename='.$path);

header('Content-Length: '.$size);




Traditional Code sometime fails on some browsers or OS 😉
PHP Developer can trust PEAR 100% 😀



$d = new HTTP_Download();

$d->setContentDisposition( 'HTTP_DOWNLOAD_ATTACHMENT', 'svnlabs.csv' ); // set file name

$d->setContentType( 'text/csv' ); // set file type




PHP PEAR File Download Package

SVNLabs Tools

HTML2CSV converts html/xhtml to csv/xls.

VMG2TXT converts Nokia VMG message file to text file.

VCard Parser Extract information from VCard.

HTML2RSS converts html/xhtml to rss/xml feed.

Amazon S3 upload file to Amazon S3 Bucket.

CSV Mapper Import CSV file after adjusting Columns.

JavaScript Twitter Bird

a2zVideoAPI – search videos with page link

EBook Search Engine

Google Map Info Window

PHP Syntax Highlighter.

Backup mysql database to amazon S3.

Pretty Print JSON

We can use function json_print() to explore JSON data, since JSON has no spacing or indentation. The function json_print() make JSON data to display in the human-readable format.


function json_print($json) {

    $result      = '';
    $pos         = 0;
    $strLen      = strlen($json);
    $indentStr   = '  ';
    $newLine     = "\n";
    $prevChar    = '';
    $outOfQuotes = true;

    for ($i=0; $i<=$strLen; $i++) {

        // Grab the next character in the string.
        $char = substr($json, $i, 1);

        // Put spaces in front of :
        if ($outOfQuotes && $char == ':' && $prevChar != ' ') {
            $result .= ' ';

        if ($outOfQuotes && $char != ' ' && $prevChar == ':') {
            $result .= ' ';

        // Are we inside a quoted string?
        if ($char == '"' && $prevChar != '\\') {
            $outOfQuotes = !$outOfQuotes;

            // If this character is the end of an element, 
            // output a new line and indent the next line.
        } else if(($char == '}' || $char == ']') && $outOfQuotes) {
            $result .= $newLine;
            $pos --;
            for ($j=0; $j<$pos; $j++) {
                $result .= $indentStr;

        // Add the character to the result string.
        $result .= $char;

        // If the last character was the beginning of an element, 
        // output a new line and indent the next line.
        if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
            $result .= $newLine;
            if ($char == '{' || $char == '[') {
                $pos ++;

            for ($j = 0; $j < $pos; $j++) {
                $result .= $indentStr;

        $prevChar = $char;

    return $result;

// Uses....


echo json_print($json);


Related JSON Function: json_add()

Other Resources:

Knowledge Base – It is little use to dig a well after the house has caught fire… SAVE knowledge like Money 😉

Amazon E-Commerce Service or ECS

Amazon’s ECS is very good service for accessing Amazon’s product database. We can register to this web service quickly, It provides a free access key to access Amazon Store.

Amazon have rich set of web services 🙂 Web Services are used to access DATA over cross platform environments.

Using ECS-driven websites and applications, we can earn commissions by advertising items for sale by Amazon.

Amazon E-Commerce Service can be used to get the information from amazon such as product name, images, availability, ratings, description, specifications, similar products, and more.

We can use PHP to consume web service using PEAR, REST, SOAP and XML etc.


There is one thing which gives radiance to everything. It is the idea of something around the corner.

Override PHP Function

PHP have PECL (PHP Extension & Community Library) function to override built-in functions by replacing them in the symbol table.

bool override_function ( string $function_name , string $function_args , string $function_code )


  1. <?php
  2. override_function(‘strlen’, ‘$string’, ‘return override_strlen($string);’);
  3. function override_strlen($string){
  4. return strlen($string);
  5. }
  6. ?>

The above function “override_function()” require APD i.e. Advanced PHP Debugger.

We can find more about APD here…

Linux users can install apd using below command

# pecl install apd

There is an alternate way to override PHP functions, we can use below class “override” to override any built-in PHP function if PECL is not installed on server 😉


  1. <?php
  2. $or = new override ();
  3. $or->override_function(‘strlen’, ‘override_strlen‘, ‘return override_strlen($string);’);
  4. function override_strlen($string){
  5. return strlen($string);
  6. }
  7. ?>




$url = '';
$override = new override();



if ($over_func_name = $override->override_check('file_get_contents')) {
    $result=call_user_func($over_func_name, $url);

function fileGetContents($url)
  /// statements



PHP Function OverRide Class


class override 

var $functions = array(); 
var $includes = array(); 

function override_function($override, $function, $include) { 
 if ($include) { 
 $this->includes[$override] = $include; 
 else if (isset($this->includes[$override])) { 
 $this->functions[$override] = $function; 

function override_check($override) { 
 if (isset($this->includes[$override])) { 
 if (file_exists($this->includes[$override])) { 

if (function_exists($this->functions[$override])) {
 return $this->functions[$override]; 
 return false; 
return false; 


Make a habit of creating things modular, that means “pluggable” and “unpluggable”.

a2zVideo API

Welcome to the a2zVideoAPI wiki!

This API supports video links to get video information like Embed Code, Video Thumb, Video Title, Video Description etc.

How to use a2zVideoAPI:

1. Download “api.php” from

2. API require PHP with CURL extension.. Setup / Upload “api.php” to your web server

3. Modify “api.php” for API Video server
curl_setopt($ch, CURLOPT_URL, ‘’);

4. There are currently 3 formats for API response

b. XML

$post = array( ‘url’ => “”, ‘format’ => “html” );

5. You have to use valid video page url like “” with format “html”, “xml” and “json”

6. Enjoy with

Follow me….


Subscribe me….

PHP Debug Log – Trace Errors

Hello Friends,

I read some where “Quality is not a product.. it is a process 😉 ”

I think process is hard-work we do and product is final result we get.

But how we make our process to get a good product, as a LAMP developer I think track processes “Debug Log” is good sort of tool for monitoring programs.

Trouble shooting is quite simple with Log Files. Log file can be used with analysis tools, it’s possible to get a good idea of where errors are coming from, how often errors return.

Here you can see a simple PHP script to trace PHP programs…


function debugLog($log, $text)
$log_dir = dirname($log);
if( !file_exists($log_dir) or !is_dir($log_dir) or !is_writable($log_dir) )
return false;

$write_mode = ‘w’;
if( file_exists($log) && is_file($log) && is_writable($log) )
$write_mode = ‘a’;

if( !$handle = fopen($log, $write_mode) )
return false;

if( fwrite($handle, $text. “\n”) == FALSE )
return false;


Debugging Tools:

We can’t imagine processes without Log File 😉