Tag Archives: php

getId3 – PHP library for audio contents

I recently use getId3 library to manipulate audio files from PHP. It is very accurate than FFMPEG. For example, FFMPEG is not helpful for audio files having VBR (Various Bit Rate).

It returns error

max_analyze_duration reached


“Estimating duration from bitrate, this may be inaccurate”

But by using getId3, we can retrieve detailed information about a particular audio file (WAV, MP3 or any)

This library can be used for any kind of medias.
You can download it from http://getid3.sourceforge.net/

– Sajith

Explore a PHP class object

If you develop website using some framework (Symfony, Codeigniter or Zend etc), you need to play with several system defined objects like routing objects, session objects etc. To see what are the functions available inside an object on run time without referring the parent class documentation, here is a trick:

print_r( get_class_methods(get_class($YourObject)));

Now you can try each functions. This will save a lot of your time without going to the definition.

I use this method, when I develop using symfony to explore an object, eg: $this->getRequest() , to know what are the other functions I can call using this getRequest()

Keep it simple !


Symfony 1.4 + Codeigniter = Symfony 2

Recently I tried Symfony 2 Sandbox for one of my projects. I realised this fact that Symfony 2 is so powerful because they restructured the Symfony 1.4 architecture and made a system like Codeigniter Framework.

I wrote a post some months back about Codeigniter vs Symfony here.

I need to re-edit that post now, because, the drawbacks I mentioned about Symfony (Advantage of Codeigniter over Symfony) is now rectified in Symfony 2.

Symfony was based on naming conventions till 1.4 (like, indexSuccess , deleteSuccess etc) but now in Symfony 2, like Codeigniter   you can mention the name of the view from controller.

The features like view inside view (instead of partials), controller inside view (instead of components) etc are really super in terms of template flexibility.

The Bundle method in Symfony 2 is adapted from the way of codeigniter libraries. (use_library)

The Bundles method also helps in reducing memory conceptions, which Symfony was being blamed for long.

Also the advantages of php 5.3 like namespace, use etc makes Symfony 2 , memory configurable.

The advanced template controller will help to play with any external templating systems very easily. The concept of slot is well used in Symfony 2.

The drastic change in Symfony folder structure will make Symfony developer hard to switch from Symfony 1.4 to 2. But once it is settled, it will be also hard  to go back.

The Symfony team claims that Symfony is faster than any other existing PHP framework available in the market. Must be true !!  But in the comparison page,   they avoided Codeigniter.  What could be the reason ?

– Sajith

Facebook Graph API – The missing part


As you all know recent changes in privacy issues made Facebook to change their basic API and added some security concerns. From my best practise, most of the old applications are safe, but you will be in trouble when you create new application. By default you cannot access user’s photos, profile pictures , albums etc. If you continue with old REST API, you may face this problem. You will get an empty array or json string when you call photos.getAlbums function.

If you test these functions from Facebook Console Tool:


It returns real value when you select old applications and returns empty string [] if you select your newly created Facebook app.

To get all those support, you need to use new Graph API

But if you follow the same steps mentioned in that official document, you will still get this empty string problem. Because, in the basic authentication call, there is no permission type is mentioned. You can only see a basic message with Allow or Deny button.

According to that document, as the part of authentication, you need to call this url with your client id and redirect url and it returns an access_token after a #

You need to use this access_token to request all other functions, eg:

This call will work for most of the requests except photos or albums. So the mistake in these calls are the permission.

Here is the correction:

Here we pass perms parameter to set different permission and if you use the access_token after this request , you can access user photos and albums. You can see another permission popup with album and photo access.

Here is the list of such extended permissions in Facebook.

This is the problem when you use new Javascript SDK for graph API, or when you try to integrate these API in PHP or PERL or any other Server side scripting language from the scratch.

If you use new Facebook PHP Graph SDK , you cannot get these problems, but there is still another hidden problem if you continue testing code by the example provided by them.

It is my next POST . See you at there



Facebook Graph API for PHP


Like the old REST API, you don’t need to add 2-3 files for Facebook PHP SDK. The new graph api comes in a single file which is located at http://github.com/facebook/php-sdk/

Copy the facebook.php file in to your webroot and include this file in your php code.


To work fully functional, you need CURL and JSON installed in your server. To check this use phpinfo() function.

To make sure, these missing is the main problem, add  exit(‘Curl error’); just above the line   throw new Exception(‘Facebook needs the CURL PHP extension.’); in facebook.php file.

Same for JSON.

The Linux way of installing CURL is :

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

To install JSON in your linux machine, follow these steps:

  1. pecl install json
  2. Add json.ini file in /etc/php.d/
  3. edit json.ini (in VI) and add this line: xtension=json.so
  4. Save the file and restart appache (/etc/init.d/httpd restart)  or apache2 restart depends on your linux OS

See the example.php file in php-sdk from Github, if you call getSession function, you only get a NULL string if you are not logged in proper way. So I recommend to redirect into login page if there is no session available.

Here is the change:

if (! $facebook->getSession()) {

header(‘Location: ‘.$facebook->getLoginUrl());


Then try the rest of the part as per example.php , it will work

Good Luck


PHP Session problem with cloud server

There is a very strange issue with PHP session when you prefer session to save in files other than database (normal session).

The problem is: some times you can access all the saved session values from $_SESSION and sometimes it returns a empty array.

If you refresh 10 times, perhaps 4 times you will get session and 6 times you will get it empty.

The problem is not due to domain level security or session expiry . It is due to session file location. If you run a phpinfo() function in any of your page, you can see there is a part of sessions. There you can see a session variable session_save_path and it will be pointing to /tmp/ or /etc/somefolder or /var some folder inside the linux file architecture.

Since at clouds, different servers server at different time, some server can see the exact saved files in that location and some server cannot. (Since /tmp etc directories are not shared among them)

Solution:  Call the below php function and set session file path inside your web root . You need to call this function before your session_start() call



For windows users as well, this is the solution. This problem occurs in ASP application as well.