Posts Tagged ‘howto’

PHP, Suhosin and POST data

January 9th, 2012 1 comment

Last week one of my clients reported an issue showing some notices spilled by the application on their development and QA servers. After some regular debugging process, we noticed that the application is not receiving the complete POST data.

Solution was simple, open php.ini, check and increase the value for post_max_size. BANG!!! No change (ofcourse apache was restarted after change in ini). Some more time was spent debugging various things. Even the stupidest thing like whether browser is sending full data to server was also checked. But nothing helped. We again started scanning phpinfo for some help when suddenly we noticed that the servers were having Suhosin patch installed and active (suhosin.ini was a part of additional .ini files).

Suhosin is an advanced protection system for PHP installations. It was designed to protect servers and users from known and unknown flaws in PHP applications and the PHP core.


We started scanning phpinfo for Suhosin specific settings … EUREKA … we found the following –

suhosin.request.max_vars = 200 = 200


Suhosin controls the number of variables that can be passed to a PHP script no matter what you set for post size in php.ini. The default value of this setting is 200 which means your PHP script will only see the first 200 values in $_POST array. All other data is silently truncated. We got this value increased to the one we needed for our script and everything was back to normal.

I spent quite a long time in finding and solving this issue and thus decided to quickly blog about this. Hope this tip will help someone save their quality time.

P.S.: Suhosin has lot of other configurations that may affect your scripts in some way. So, if you get into such a situation where everything looks normal in php.ini, look for Suhosin and its settings. You may find the solution to your problem just like I did.

Tags: , ,

Multipart posting with Apache Benchmark

March 21st, 2011 5 comments

Last week I wanted to load test an upload functionality created for one of the projects. The testing team was busy with other stuff so I decided to do it on my own. Being a hardcore programmer and someone who has never used any of the regular testing tools (read M$ Window$ based tools) I had the only option of using Apache Benchmark on my Ubuntu 10.10

Since I had already used ab (the Apache Benchmark command name), I was pretty confident that within few minutes I will be done. But multipart form posting wasn’t as straightforward as I had thought. My initial assumption was to provide a file path to -p option of ab and it would handle the stuff required for multipart posting. Unfortunately that wasn’t the case. I realized that I had to provide a file name but it should contain the complete information about the data to be posted. In other words, I had to manage the boundary required for multipart posting.

After some research and this small but important tip, I managed to prepare the POST data in the required format along with the correct Content-type required by Apache Benchmark. The final command looked like

ab -n 10 -c 2 -C PHPSESSID=rk53j7gsrmaiuc3gvo86ipltr1 -p /var/www/post_data.txt -T "multipart/form-data; boundary=1234567890"

Following is the breakdown of options provided to the command –

I provided the cookie information (option -C ) along with the command since my upload script checks for authentication.
-p allows me to provide a file name which contains the complete information about the data to be POSTed along with multipart boundaries.
-T is for Content-type header. This is where I also tell ab about the boundary in my POST data along with the standard multipart/form-data content type.
And then finally the URL of where all the data has to be posted.

The contents of the post_data.txt file are

Content-Disposition: form-data; name="ID"

Content-Disposition: form-data; name="videofile"; filename="ab1_pod.avi"
Content-Type: video/x-msvideo

[base64 encoded file content here]

Remember that the format of the file should be exactly the same (your boundary label can be different than mine though). Even if you miss a single new line or add an extra new line somewhere then you won’t get the expected results.

Finally to base64 encode the file to be posted, you can simply use PHP code as follows and paste the content in the above placeholder.

echo base64_encode(file_get_contents('/home/aditya/Videos/my_video.avi'));

That’s it. Happy testing.
As always, comments and suggestions are most welcome.

Changing default browser in Kubuntu

August 6th, 2009 6 comments

Yes, I am writing a blog post for a task that sounds very simple to achieve – just with a click of a button. But this is not true, atleast  with Kubuntu 9.04. If  you are coming to this post through search engine then you have already gone through this pain. If not, give it a try 😉

Surprisingly, the browser’s functionality of setting it as default doesn’t work in Kubuntu. At the same time, changing it manually from System Settings -> Default Applications doesn’t seem to work either.

To set one of your browser as default browser, you have to run the command

$ sudo update-alternatives --config x-www-browser

You will see the list of browsers currently available in your system and then you will enter the number for the browser you want to set as default. My console with 3 browsers was something like follows

$ sudo update-alternatives --config x-www-browser

There are 3 alternatives which provide `x-www-browser'.

Selection    Alternative
+        1    /usr/bin/konqueror
2    /usr/bin/firefox-3.0
*         3    /usr/bin/google-chrome

Press enter to keep the default[*], or type selection number:

That is it. Enter the number for the browser you like and hit ENTER. You have your browser set as default.

Migrating from Evolution to Thunderbird

July 2nd, 2009 Comments off

A colleague of mine who was using Evolution mail client since past few years finally decided to start using Thunderbird. But the biggest challenge was moving his emails and contact list to Thunderbird client as there is no builtin functionality available in Thunderbird for the same.

As usual Google came to the rescue and I found a nice article which I thought is worth sharing with everyone. This article written by Damien provides step-by-step assistance in migrating your emails, contacts, calendar, tasks and other things from Evolution to Thunderbird.

The migration process went very well after following all the steps given there. We were mainly interested in mails and contacts but I am sure the other data can also be migrated with same ease.

If you also find the article helpful, do thank him on his blog.

Gave up waiting for root device – Kubuntu

July 1st, 2009 3 comments

If you are consistently getting the Gave up waiting for root device error while booting your ubuntu/kubuntu box, its time to make a small change to your grub menu file.

But to be able to do that you should atleast login to your account. As a first step try to reboot your machine a few times. If this still doesn’t take you any further, wait for sometime on the screen showing above message and then type exit on the shell which will then take you ahead. If not, wait for some more time and then try again.

Once you are through, login to your account and then edit /boot/grub/menu.lst and add rootdelay=90 in as a kernel parameter. The final entry should look something like

kernel /boot/vmlinuz-2.6.27-11-generic root=UUID=105e82bc-3131-428f-ad9e-aa5f55833421 ro quiet splash rootdelay=90
Tags: ,

pidgin not connecting to yahoo

June 25th, 2009 Comments off

Well … it looks like Yahoo! is once again changing its protocol and everytime this happens, we, the *nix users suffers most as there is no official version of Yahoo! messenger available.

I am using Pidgin (formerly Gaim) since last 6 years and have gone through this pain of not being able to connect to Yahoo! for few days when they are changing the protocal. The time has come again as I was not able to login to my Yahoo! account since yesterday.


Being a Kubutu user, I tried to update my version of Pidgin from 2.5.5 to the latest 2.5.7 but unfortunately, it is still not available in kubuntu repository. But I found the alternative and thought of sharing with all those who are facing the same issue. Adding the Launchpad repository to the apt sources did the trick for me. I used the following commands on my Kubuntu 9.04 to achieve this –

First run:

$ sudo apt-key adv --recv-keys --keyserver 67265eb522bdd6b1c69e66ed7fb8bee0a1f196a8

then open the sources file –

$ sudo vi /etc/apt/sources.list

and add the following at the end of the file

deb   jaunty main

and then upgrade pidgin

$ sudo apt-get update
$ sudo apt-get upgrade pidgin

That’s it. You can now connect to your favorite Yahoo! messenger again.

Happy chatting.

Blocked updates in Kubuntu

June 24th, 2009 5 comments

Now it’s more than two months since my transition from Fedora to Kubuntu 9.04 (Jaunty Jackalope). I am enjoying trouble free running on my desktop as well as EEEPc 1000HE since then.

The one thing I am following regularly is, keeping the system uptodate using the default package manager, KPackageKit. Everything was going fine till yesterday when it started showing me 4 blocked updates. I was wondering if the updates are blocked, why are they being shown in the first place.

There was no way to remove them from the list and the KPackageKit just stuck there.

After searching for a while, it was clear that this is a issue with KPackageKit which cannot update the packages which has some other dependencies and straightaway marks them as blocked.

The only solution to get rid of these blocked updates is to do the command line upgrade by doing:

$ sudo apt-get update

followed by

$ sudo apt-get dist-upgrade


Working with multiple Firefox profiles

March 3rd, 2007 1 comment

From past one month or so I was desperately looking for something which will allow me to open multiple Firefox instances with different profiles. At first it looks like an easy task to accomplish but at the end leaves you with scratching your head.

Some of you may think that its as simple as writing a command

firefox -ProfileManager

at that’s it.
But no, this won’t work. Even if you create multiple profiles and try to open it through profilemanager it will still load firefox with same profile.

To open Firefox with another profile you should use the command

./firefox -no-remote -P profile2

But remember that your first Firefox instance must be opened without using the -no-remote option. Only then you can open multiple Firefox with different profile.

I hope this will make the life easy for lot of developers using Firefox

Tags: ,