Install PHP 5.4 from DotDeb

In case if you want have latest php-5.4 both in CLI and with Apache-2.x it is better to install it through apt-get
You need to add these source to sources.list file:

deb squeeze all
deb-src squeeze all
deb squeeze-php54 all
deb-src squeeze-php54 all

If you are getting this error

W: GPG error: stable Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY E9C74FEEA2098A6E
W: GPG error: squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

you need follow such steps:

gpg --keyserver --recv-key 89DF5277
gpg -a --export 89DF5277 | sudo apt-key add -
gpg --keyserver --recv-key ABF5BD827BD9BF62
gpg -a --export ABF5BD827BD9BF62 | sudo apt-key add -
sudo apt-get update

HowTo Compile and Install php-5.4.x on Debian OS (squeeze)

Recently I was trying install latest PHP 5.4.x (at the moment of writing this is 5.4.10) version on my stable Debian OS (v6.0-squeeze-32bit).
As far as you may know, stable Debian proposes PHP-5.3.4 as latest available release. I wanted to use embedded into PHP-5.4 web-server.
I was thinking that install PHP-5.4 would be faster process then configuring new virtual host in Apache. Yep, lazy me! 🙂
Well, spoiling the story, I would like to say, that the overall process took 2-2.5 hours from me before I was able to launch my scripts.
To be honest, that was my first time when I was compiling PHP from source, and I feel I got great experience with that!
But okay, let’s look at the process step-by-step.

First of all, you may need install “libxml2-dev” linux library (don’t remember why, though :-)).
Oh, wait! Looks like it needed for you be able to configure you PHP installator.

sudo apt-get install libxml2-dev

I also believe that most web developers need to use DB with theirs scripts, thus they may need PDO php extension.
So, you need to compile PHP with this directive:

configure --with-pdo-mysql --with-mysql

(see for more details)

Usually, good devloper uses debug tools extensively. As we all know most popular PHP debugger is a xdebug.
This package could be installed from pecl repository.
Before asking pecl to install xdebug, make sure you have php5-dev package installed in your system. With that package phpize is being shipped, which is required to install PHP extensions through pecl.
If you don’t have php5-dev install, you are going get this error message:

ERROR: `phpize’ failed

and here is your next command:

sudo apt-get install php5-dev

After that, you will be able install xdebug extension with help of pecl:

sudo pecl install xdebug

Next. Let’s assume you work with not only documents written solely in English, but with some other languages (Italian, Portugeese, Russion, Dutch, etc.)
Also let’s assume you need to handle dates written in non-english format (btw, about that look for my article about how one can handle dates written in languages different from English). php5-intl extension comes to help! Here you will find information how to enable this extension:

configure --enable-intl

If PHP’s configurator shows error message

“configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.”

you need install this Linux package:

apt-get install libicu-dev

These are development files for International Components for Unicode.

Next, it may happen that you need load remote http resources. Usually, that is done with curl (php5-curl).
I was not enable that extension because faced such message:

configure: error: Please reinstall the libcurl distribution

In such case you need install this Linux package:

sudo apt-get install libcurl4-gnutls-dev

(thanks to

In case if you need to deal with multibyte encodings and use PHP’s functions prefixed with mb_*, you need enable that as well:

configure --with-mbstring

Okay, as I said, after couple hours of fight I was able to finish with this configuration options and directives:

sudo ./configure --with-pdo-mysql --with-mysql --with-curl --enable-intl --enable-mbstring=all

As I said at the beginning, I was hoping that install PHP-5.4 would be faster then configure virtual host. How far away from truth was I!..
But I do not regret about my choice, because now I feel strong in believe that I have mastered some important things and have grown my professional level!

Fell free to add comments and ask things that left unclear for you.

Fn keys stopped work Lenovo on Thinkpad Edge with Debian

Once upon a time ALL functional keys (brightness, volume control, camera, microphone, wi-fi) of my Lenovo Thinkpad Edge 15 suddenly stopped work. I’m not a guru-guy in all that Linux’s low-level bullshit like acpi events, etc. So, I periodically tried to find a solution for the problem in the INet, but having no idea what to search for – I was searching for acpi, fakekeys, Debian (that is the OS installed on my laptop), – I didn’t find any solution. But with help of luck suddenly I discovered one great forum about Ubuntu OS, where there was an unexpected solution of absolutely similar trouble…
Well, all the deal is about BIOS issues on Lenovo Thinkpad Edge!! 🙁
So far, to restore previous BIOS’s state, all you need is unplug an AC adapter and remove battery for approx. 1 minute or a little bit longer. That is all! Fn keys are work again like a charm!
Thanks to guys who proposed the solution!

Download audio from VKontakte

Here is a tiny helper script allowing to create a list of URLs of mp3 files which then could be fed to smth. like Download Master.
This script need to be launched in Firebug’s console (extention for the FireFox web browser, oriented at programmers) while you are on the “My audio” page of the VK’s web site.
As a result of execution you will get a list of links to audio files of your playlist. Then you just need to copy that list to TXT file after what the file need to be imported into DM through the menu item File -> Import. That is all! Files are being downloaded! The only issue is file name. What you will get is a unique ID and not human-readable title. If you wish you could rename all files manualy, otherwise you could write another script, let’s say using PHP programming language. That script should read ID3 tags of each file and use meaningfull title extracted from the tag as new name for your file.
Well, here is the script, actually:

var hiddenFields = document.getElementsByTagName("input");
var mp3s = [];
function getHiddenField(elem, index, collection){
    if(elem.getAttribute("type") == "hidden" && (/audio_info\d+_\d+/).test(elem.getAttribute("id"))){
for(var i=0; i < hiddenFields.length; i++){
    getHiddenField(hiddenFields[i], i, hiddenFields);

Form builder – entity field: “Class BundleAliasName:EntityClassName does not exist “

After having symfony-2.1 updated to the version from trunk (symfony-2.1.0-beta4) one of my forms crashed. That was the form in which I used entity field type with “class” option set not to fully-qualified name of Entity Class but a bundle-aliased one:

                 'class' => 'BundleAliasName:EntityClassName',
                 'multiple' => true

The code threw exception with message like this:

“Class BundleAliasName:EntityClassName does not exist”

If “class” has been set to full path to the Entity class:

    'class' => 'Full\Bundle\Path\Entity\EntityClassName',

then all worked just fine.
So I opened the ticket for the issue and it turned over that the origin of this issue not symfony, but rather Doctrine related! You only need to upgrade your Doctrine version to 2.3 and that is all.
Many thanks to Christophe Coevoet who helped me to resolve the issue by answering through the comment on github!

How to upgrade project from symfony-2.0 to symfony-2.1

Originally, I created a project on the symfony 2.0 version without the vendors (standard edition). All dependencies were installed by

php bin/vendors install

The project was hosted on the git-repository.

Sidenote: when this post is being written, symfony 2.1 was in beta testing.
However, the main trend has been clear and significant changes in the API was not forthcoming.
One of the key innovations in symfony 2.1 – use Composer .
On the Symfony framework website one can find a description of the process of creating a new bare project, but there is no information about how to upgrade an existing one.

Let’s begin, sir.
Initially I tried to just copy the contents of the file composer.json, located in the root directory of the Symnofy framework hosted on github, and run

php composer.phar update

but there are no all the dependencies required for the normal functioning of the project.
That is why I just decided to create a new “empty” project:

php composer.phar create-project symfony/framework-standard-edition path/

in a separate branch of my git-repository and then merge in changes from the original branch with the version of symfony-2.0.

I confess that I had to resolve conflicts in the files apps/AppKernel.php, files config.yml, security.yml and others.
But it was not too difficult task.
Also, it is necessary to upgrade all of the additional bundles you may use to the appropriate version for symfony-2.1
For example, for FOSUserBundle ( # installation)
add this to you composer.json

    "require": {
        "friendsofsymfony/user-bundle": "*"

and then execute the command

php composer.phar update

Also you need to make changes according to the instruction in the forms files, and other places. But all depends on your situation – what features are being used in your project.

So after all the steps above, the project has started successfully.
One of the first visible changes is added some beauty to the web-debug-toolbar – there appeared tooltips with summary information for each of the sections of toolbar. Those tooltips appear when you hover the mouse on the appropriate icon.

PS: A few days ago I found another method of how to upgrade to symfony-2.1:

Composer – minimum-stability changed to stable by default

Today (July 4, 2012) Composer switched default stability inside it from dev to stable.
More details here and here.
What it means is that by default Composer will ignore packages with RC, beta, alpha or dev stability.
I found this problem when tried to update my project’s (based on symfony-2.1.x framework) dependencies. At the time of this post being written, symfony-2.1 is in beta stage.

rodush@debian:~/gtrs$ php composer.phar update
Updating dependencies
Your requirements could not be solved to an installable set of packages.

Here is what composer suggested (and what actually helped – the 2nd item in the list):

Potential causes:
– A typo in the package name
– The package is not available in a stable-enough version according to your minimum-stability setting
see for more details.

So, to avoid the problem described above, the easiest way is to add
"minimum-stability": "dev"
to you composer.json file.

symfony 2.0 FOSUserBundle – overriding form produces “Could not load type” error

If you are using FOSUserBundle with symfony 2.0 and you need to override any of the forms of proceeding “included” with this plugin
then, without a doubt, you’ve read this note:
After updating your page can happen unfortunate situation – the error message “Could not load type ….” (dots here will be the alias which you gave to your custom form type).
It seems to be in the file app/config.yml all right with the paddings (meaning configuration of the fos_user service), and a configuration file for your service service.xml (service.yml) (in CustomUserBundle) is described correctly, and everywhere the same alias, getName () and so on … but still the same error. Doesn’t it? It does not matter! 🙂 There is a solution to your problem! Read on, and everything will be easy!

To understand and properly use the services and dependency injection in symfony 2.x, highly recommend reading this and this. The bottom line is that in order to see your symfony framework services and extensions, you must provide information about the configuration of your bundle.
You can do this in two ways.

1. The standard configuration of the service.
You can specify your services in a configuration file (e.g. services.yml) that lives in your bundle and then import it from your main application configuration. This is really easy, quick and totally effective. If you make use of parameters, then you still have the flexibility to customize your bundle from your application configuration. See “Importing Configuration with imports” for more details.

- {Resource: parameters.ini}
- {Resource: security.yml}
- {Resource: @CustomUserBundle/Resources/config/services.xml}

2. The semantic description of the configuration.
This is the way configuration is done with the core bundles (as described above). The basic idea is that, instead of having the user override individual parameters, you let the user configure just a few, specifically created options. As the bundle developer, you then parse through that configuration and load services inside an “Extension” class. With this method, you won’t need to import any configuration resources from your main application configuration: the Extension class can handle all of this.
The second method is described in details in the second of the links above.

So, returning to the nature of our error. The point is this: it may happen that the “Custom” bundle for the user (User) you have created manually (by copying from existing Bandle all necessary files and directories) rather than using a console command Symphony (generate:bundle).
In this case, you might have forgotten to create the directory DependencyInjection and CustomUserExtension.php and Configuration.php files uder it.
Or, if you did not intend to use semantic configuration, you jsut forgot to import your CustomUser service’s configuration file into your main config file.

That’s it. Now you know about the two possible solutions to this problem. Then it’s up to you which way to choose – simple (through imports) or flexible (through the extenstion and semantic configuration).

JavaScript – how to trim leading or trailing spaces of a string

There are tons of publications on the subject in Internetm but let me put my “50-cents” on this.
The problem is that in javascript there is no built-in function to trim leading and trailing spaces on a string.
This can be easily implemented by adding required method to the javascript’s String object:

String.prototype.trim = function(str) { return str.replace(/^\s+|\s+$/g, ""); }