toptal-blog-1_C

SQL Database Performance Tuning for Developers

Database tuning can be an incredibly difficult task, particularly when working with large-scale data where even the most minor change can have a dramatic (positive or negative) impact on performance.

In mid-sized and large companies, most SQL database tuning will be handled by a Database Administrator (DBA). But believe me, there are plenty of developers out there who have to perform DBA-like tasks. Further, in many of the companies I’ve seen that do have DBAs, they often struggle to work well with developers—the positions simply require different modes of problem solving, which can lead to disagreement among coworkers. (more…)

Read More

php-elephant

Installation PHP5-FPM with Apache 2 in Ubuntu 14.04/10, 15.04/10

PHP FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.

These features include:

  • Adaptive process spawning (NEW!)
  • Basic statistics (ala Apache’s mod_status) (NEW!)
  • Advanced process management with graceful stop/start
  • Ability to start workers with different uid/gid/chroot/environment and different php.ini (replaces safe_mode)
  • Stdout & stderr logging
  • Emergency restart in case of accidental opcode cache destruction
  • Accelerated upload support
  • Support for a “slowlog”
  • Enhancements to FastCGI, such as fastcgi_finish_request() – a special function to finish request & flush all data while continuing to do something time-consuming (video converting, stats processing, etc.)

(more…)

Read More

mysql-no-password

MySQL Command line login with inline password & Executing SQL Statements

Login with inline password in command line

Normally we don’t need to use inline password to login or we don’t do that. But sometimes it is a must when you need to login from a bash script or when we need to execute some SQL Statements from bash script or run them in a cron. If you check MySQL manual they have just included the simple command :

mysql --host=localhost --user=myname --password=mypass mydb

Or

mysql -h localhost -u myname -pmypass mydb

(more…)

Read More

Zend is the leading PHP Web Application Platform. (PRNewsFoto/Zend Technologies)

Using Zend Server’s PHP for Command line (CLI) in Ubuntu 14.10

By default when you install Zend Server, it does not allow to use PHP directly from command line though the configured PHP applications work with web server (Apache or nginx). Try:

$ php -v

It will ask you to install PHP separately.

Solution

Though you can install another PHP and use it for all command line scripts but there is a quick work around to use Zend Server’s PHP itself.

(more…)

Read More

pma-logo

Using phpmyadmin for multiple local and remote MySQL Servers

Normally we need a client software to access MySQL server whether it is remote server or local. Most of the developers who use MySQL as back end database use phpmyadmin which is a web application. But when it comes to access the remote database, we use different client applications. MySQL Workbench is the official MySQL Client application/software which does pretty much good job for most of the cases. That’s why I think most of the developers choose this. In Windows I used to use SQLYog which is not yet free. (more…)

Read More

Ubuntu_GDM_logo_alternative

Ubuntu 13.10/14.04 mcrypt missing – Fatal Error: Undefined function mcrypt_encrypt()!

I had updgraded my Ubuntu from 13.04 to 13.10 last week and everything went quite good. The only problems that I faced as developer are:

  1. Apache 2.4 was not working with default previous installation and configuration and I had to remove it (completely uninstall/purge and autoremove) and install it again.
  2. All the virtual host setting did not work. I did not go for opting to change the Include setting in apache2.conf instead I rewrote all the settings myself.
  3. Another annoying and very strange problem was that PHP and its libraries. First I had problems with installing apache module that connects to PHP. Secondly I had problems of missing mcrypt library which is required for couple of projects on my system. Particularly a project developed in Zend 1.11 and phpmyadmin did not work. I had the following error where I had written some methods for AES encryption with PHP’s mcrypt library.

(more…)

Read More

Converting PFX Certificate file to .PEM format in Linux/Ubuntu !

I don’t know if there are other ways to have a .PEM file from a PFX file in Linux (Ubuntu), but after couple of research/study in the internet, I came to find some work around. First of all what those formats are actually, let me explain what I came to understand.

PFX Format
Originally defined by RSA in the Public-Key Cryptography Standards, the “12” variant was enhanced by Microsoft. This is a passworded container format that contains both public and private certificate pairs. Unlike .pem files, this container is fully encrypted. Every time I get one I have to google to remember the openssl-fu required to break it into .key and .pem files.

PEM Format
Governed by RFCs, it’s used preferentially by open-source software. It can have a variety of extensions (.pem, .key, .cer, .cert, more). And in most cases while we need to use the private and public keys together in scripting languages like PHP then we have this format.

Converting PFX file to certificate and key format first
Openssh is the open source application to convert these. The command openssl in Linux comes with lots of other options but we will be using few here:

openssl pkcs12 -in yourpfxfile.pfx -clcerts -nokeys -out desired_certificate_filename.cer

This command extracts public key to desired_certificate_filename.cer.

openssl pkcs12 -in yourpfxfile.pfx -nocerts -nodes  -out desired_publickey_filename.key

This command extracts private key to desired_certificate_filename.key.

PEM File
Now lets combine both into one .pem file.

cat desired_certificate_filename.cer desired_certificate_filename.key > desired_pem_filename.pem

Hope this will help !
:)

Read More

Zend Framework – Using FlashMessenger Helper outside of Controller

I was struggling to check session expiry for Zend_Auth and redirect the users to login page with certain message to let them know the session has expired. Found following code to limit the session expiry time:

$authns = new Zend_Session_Namespace(Zend_Auth::getInstance()->getStorage()->getNamespace());
$authns->setExpirationSeconds(60 * 15); // for 15 minutes

Then the major problem that I encountered while setting the messages using Flash Messenger plugin. Though I am not quite experienced Zend programmer but since last couple months, I had used the Flash Messenger plugin directly from within action controllers. It seems the plugin is automatically loaded in the action controllers. But I was about to check the user’s login session expiry in one of my own custom plugin which extends Zend_Controller_Plugin_Abstract as follows:

class FHF_Acl_AccessCheck extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        /**
         * @author Raju Gautam
         * Check login session and throw some message for expiry
         */
        $hasIdentity = Zend_Auth::getInstance()->hasIdentity();
        if(!$hasIdentity && $module != 'user' && $controller != 'user' && $action != 'login'){
            // set some message and login form
        }
    }
}

Where I have checked if the the Zend_Auth has null identity and show/load the login form with some message. But while setting the message first I tried:

$this->_helper->FlashMessenger->addMessage(array('error' => "Session expired, please login again !"));

But this did not worked, threw error message instead.

So I researched then found in one of the pages in the internet and found the following solution:

class FHF_Acl_AccessCheck extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        /**
         * @author Raju Gautam
         * Check login session and throw some message for expiry
         */
        $hasIdentity = Zend_Auth::getInstance()->hasIdentity();
        if(!$hasIdentity && $module != 'user' && $controller != 'user' && $action != 'login'){
            $flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'FlashMessenger' );
            $flashmessenger->addMessage (array('error' => 'Session Expired ! Please login again !'));
            $request->setModuleName('user')
                    ->setControllerName('user')
                    ->setActionName('login');
        }
    }
}

So if anyone wants to set the flash messages from outside of the action controllers, then you should use something like this using Zend_Controller_Action_HelperBroker class and its static helper getStaticHelper.

$flashmessenger = Zend_Controller_Action_HelperBroker::getStaticHelper ( 'FlashMessenger' );
$flashmessenger->addMessage (array('error' => 'Session Expired ! Please login again !'));

With this, you can get any plugin outside of the action controllers.

Hope this will help others struggling for the same.

Good luck!

Thanks.

Read More