My tools on Linux

Update 2016-01-16

Development of Crunchbang has now stopped. There are a few community spin-offs available, Bunsen Labs and Crunchbang++. I’m now using a netinst version of Debian at home with the i3 window manager, and Bunsen Labs on my office laptop. Both are working well. I’m still using the same set of software for my work, in addition to a few more, so this post is still valid.


I’ve been using Linux at home and work for over 5 months now. I’m using a Debian based distribution called Crunchbang. Over these past few months I’ve developed/programmed using multiple technologies and have gathered a collection of tools, that I use on a daily basis.

Name Type Link
Eclipse with NodeEclipse – Check Update IDE for Node.js Link
Netbeans IDE for PHP Link
Dbeaver GUI client for Cassandra and others Link
MySQL Workbench MySQL/MariaDB GUI client Link
Dia Flowchart and Diagrams Link
SoapUI Testing – API and Web Services Link
Tilda Drop down terminal Link
Meld Mergetool Link
Remmina GTK RDP Client Link
Tomboy Note Taking App Link
GMTP MTP Client Link
GIMP Image manipulation Link

Continue reading “My tools on Linux”

Handling JSON request in PHP

I’ve been working with PHP and jQuery AJAX quite a bit lately. Along with sending form data to PHP page through AJAX, I’ve written restful web services in PHP that receive data in JSON format.

In general when you are sending data through jQuery AJAX to PHP, you don’t have to specify a contentType. Depending on your type ‘GET’ or ‘POST’, PHP will nicely wrap your content into either the $_POST or $_GET global arrays. When you don’t specify a contentType the default contentType is taken as application/x-www-form-urlencoded; charset=UTF-8’.

Following is the request headers from an AJAX call without contentType specified,

To further test this, I set up the following PHP code on my server,

The response that for the above request case was,

If we put the jQuery AJAX type property as ‘POST’ we will have the following request header,

Nothing much changes. The action is specified as POST and the data is no longer a part of the request header. The response from the server is following,

Obviously, PHP has no issues parsing content of type – application/x-www-form-urlencoded; charset=UTF-8. As soon as it sees that contentType, it checks the action and packs the data nicely into either $_GET or $_POST.

Let’s now talk about JSON data. In general, restful web services accept data of type JSON. When sending data via JSON the contentType for jQuery AJAX is application/json; charset=UTF-8

This is the request header,

When PHP receives this data and looks at the content type, it’s not quite sure how to process it, so it leaves it alone. In this case the action – ‘POST’ or ‘GET’ doesn’t matter. You’ll notice that $_POST or $_GET both, are empty arrays. Now, it’s up to you to read this data and parse it.

The code above, reads the data from PHP’s input stream. Since we have passed a JSON string, we decode it, which converts it to a PHP array and stores it in $app_json. If the data you send is not in a correct JSON format, $app_json will have false.

When we echo our response, we get the following on the client side,

I set up a small project to illustrate what has been written here. You can find it over on my github page.

get_results PHP function not working on CentOS

There are instances where the PHP function – get_results will not work on CentOS (this maybe the case with other Linux based operating systems as well). I faced this issue while deploying a project on CentOS which was originally developed on Windows. All my INSERT, UPDATE and DELETE database statements were working properly, but bulk SELECTstatements had issues. Closer inspection narrowed down the problem to the get_results function.

I came across this on the get_results PHP documentation page –

I was able to determine if mysqlnd driver was installed using this post on StackOverflow as reference. As expected, it wasn’t.

Here’s the relevant php code from the StackOverflow post –

Now that I new that we needed to install the mysqlnd driver, here are the steps that I followed to get the mysqlnd driver working on CentOS,

After installing the mysqlnd driver the get_results function worked just fine.