Monday, September 23, 2013

PHP Mysql Fetch Association Vs Fetch Array Vs Fetch Object Performance Analysis

In this analysis we will see how the 3 main Mysql data fetching methods in PHP performance under different loads
In most programming situations regarding php-mysql you will need to fetch data from the db to  populate your application with data
There are 3 most popular methods of getting more than one data when fetched.
  • mysql_fetch_assoc() : This gets you an associative array of data.
  • mysql_fetch_array() : This returns a combination array of associative elements as well as data with numerical index.
  • mysql_fetch_object() : Returns an object with properties that correspond to the fetched row.
We are comparing the 3 methods here based on benchmark tests done by spearhead softwares on various load conditions.
In the test we run each methods result dataset containing 10,100,1000,10000,100000,1000000,10000000 data and see how fast and efficient each function operates.
Each data set contains a unique id element, int & a string element which makes it the normal set of values which is being retrieved in most normal cases.
PHP mysql fetch function performance benchmarksSource: SpearheadSoftwares.commysql_fetch_objectmysql_fetch_arraymysql_fetch_assoc10100100010000100000100000010000000-505101520253035Seconds

From this we can clearly see that the default functionality of mysql_fetch_assoc is running at a higher performance than the other 2 methods (mysql_fetch_array & mysql_fetch_object). mysql_fetch_object performance is justified as it returns objects instead of native arrays which will always bring in a better memory usages than any other kinds of output array. And for using the Object oriented result set approach the other 2 functions cannot satisfy. Lets take the case of mysql_fetch_array(); The problem here is in daily programming usages many php programmers have used the mysql_fetch_array() as such without going into the details of its usage. By default mysql_fetch_array returns 2 types of results sets as given by its default result_type value MYSQL_BOTH

  • result_type : MYSQL_NUM - which gives us only a numbered index array eg: array([0]=>'apple')
  • result_type : MYSQL_ASSOC - which us only associative array eg: array('fruit'=>'apple') where 'fruit' will be the database column name or alias used.
So when we use mysql_fetch_array we get a duplicate set of data consisting of  both numbered index as well as associative arrays which ofcourse is our performance blocker.
So when ever you are using mysql_fetch_array function always specify the return_type of the result set array needed.
And in most cases we will need an associative array during iterative data management in php so the best function to call will be as shown in the graph ,performance wise -mysql_fetch_assoc()
Hope you liked our article. If you have more ideas regarding performance in this category, do comment .

Thursday, September 19, 2013

How to Transfer Files Using PuTTY - PSCP


PuTTY is the CIT-recommended application for secure file transfer using SCP between Windows clients and Windows or Unix servers.
PuTTY is available from PuTTY.org.

Install PuTTY and Set up a Server Connection

PuTTY is the recommended SCP client for Windows client and Unix server file transfers at Cornell. PuTTY is available from PuTTY.org.
  1. Download the pscp.exe file from PuTTy.org. Click the file name and save it to your computer.
    If you want a PuTTY shell program, download and install putty.exe as well.
You are now connected to the server and can begin transferring files.

Transfer Files Using PuTTY

  1. Open a Windows command line window. On the Start menu, click Run.

    filewindowsstart
  2. In the Open box, type cmd, and then click OK.

    filewindowscmd


Add putty scp client( pscp.exe) and (putty.exe) path to windows Environment Variable

MS Windows uses a concept of paths to go searching for where programs are located on your hardware. When using the DOS box, the operating system has no context about where your programs are located on the hard drive. When using the GUI, the information about where the program is located, is contained in the Shortcut that you are clicking on.
You could start PuTTY by typing something like this:
PuTTY-cli-10.jpg
but that is too much typing for me.
We can tell Windows that the directory where the PuTTY program is and to look in there for the program as needed.

To the Control Panel System tab then

In the Control Panel, System Properties, select the Environment Variables button at the bottom:
PuTTY-cli-11.jpg
and then select Path in the System Variables section, and press the Edit button.
PuTTY-cli-12.jpg
PuTTY-cli-13.jpg
and it will look like this ( you need to be a little bit careful here not to delete the content, if you think you have mis-types then just press escape and start over), on the end of the line enter the following text exactly (including the semi colon):
;C:Program FilesPuTTY
PuTTY-cli-15.jpg
This set the path variables to include the PuTTY program directory in the search path. You only have to do this once. Windows will set the the Environment Variable permanently from now on.
You will need to logout at this point, or restart. The Path Variables are only read once at boot time.
When you come back, open the DOS box again (Ctrl-Escape, R, cmd, Enter – just to remind you), and type path to confirm the variables are in place.
PuTTY-cli-17.jpg



  1. At the Windows command prompt, enter:
    pscp source_file_name userid@server_name:/path/destination_file_name.

    For example:
    c:\>pscp june06extract wrhse@warehouse.cit.cornell.edu:/mydata/june06extract.

  2. When prompted, enter your password for the server.
Note: Complete documentation for PuTTY is on the PuTTY.org site.


Obtaining and Using PSCP

PSCP is a freeware SCP (Secure CoPy) program for the Windows command line processor. You can use this program instead of FTP for copying files to or from the Unix servers at the NBER offices. FTP is not allowed from clients outside nber.org to servers inside the firewall because FTP leaves passwords in plain-text and vulnerable to eavesdropping. PSCP should work with any host supporting SSH.

Details:

  • Download PSCP here.
  • Save pscp.exe somewhere on your hard drive. C:\windows\ is a good location in the default execution path.
  • The command line syntax is:

    • pscp [options] [user@]host:source target
    • pscp [options] source [source...] [user@]host:target

      Options:
      -p preserve file attributes
      -q quiet, don't show statistics
      -r copy directories recursively
      -v show verbose messages
      -P port connect to specified port
      -pw passw login with specified password

      source or target may be a pathname or a ~userid/filename (on the Unix side). You will be prompted for the password of `user'. This is an old-fashioned command line program - you need to open a DOS window to run it.
Copying files from your UNIX host to your Windows PC.

  • In order to copy a file from your UNIX host to your Windows PC your command line would look like this:

    • pscp username@yourhost:file.foo c:\temp\file.foo
    • This command line copies "file.foo" located in your home directory on your UNIX host to the temp directory on your C:\ drive.
Copying files from your Windows PC to our UNIX host.

  • In order to copy a file from your Windows PC to your our Unix host your command line would look like this:

    • pscp -v c:\"my documents"\file.foo username@nber.org:file.foo

    • This command line copies "file.foo" located in the "my documents" directory on your C:\ drive to your home directory on our Unix cluster.
    • Remember: Backslashes (\) for your DOS and Windows files and forward slashes (/) for your UNIX files. 

Connecting to a Samba Share (File sharing Linux vs Windows)

19.3.1. Command Line

To query the network for Samba servers, use the findsmb command. For each server found, it displays its IP address, NetBIOS name, workgroup name, operating system, and SMB server version.
To connect to a Samba share from a shell prompt, type the following command:

smbclient //<hostname>/<sharename> -U <username> 
 
root@itadmin-AcerPower-Series:/# clear

root@itadmin-AcerPower-Series:/# smbclient //192.168.2.100/shared -Uitadmin
Enter itadmin's password: 
Domain=[CHNSRV] OS=[Windows Server 2003 3790 Service Pack 1] Server=[Windows Server 2003 5.2]
smb: \> ls
  .                                  DR        0  Thu Sep 19 11:34:36 2013
  ..                                 DR        0  Thu Sep 19 11:34:36 2013
  .DS_Store                          AH    24580  Tue Sep 17 12:22:12 2013
  admin                               D        0  Wed Aug 14 20:11:47 2013
  kumar                               D        0  Thu Sep 12 17:27:38 2013
  shiva                               D        0  Wed Sep 18 08:47:51 2013
  siva                                D        0  Wed Sep  4 18:44:45 2013
  
  51203 blocks of size 2097152. 7692 blocks available
smb: \>






(or) Suppose your Linux machine user name is same as Network windows server user name, Here no
need -U itadmin(username)

itadmin@itadmin-AcerPower-Series:/$ smbclient //192.168.2.100/shared
Enter itadmin's password: 
Domain=[CHNSRV] OS=[Windows Server 2003 3790 Service Pack 1] Server=[Windows Server 2003 5.2]
smb: \> ls
  .                                  DR        0  Thu Sep 19 11:34:36 2013
  ..                                 DR        0  Thu Sep 19 11:34:36 2013
  .DS_Store                          AH    24580  Tue Sep 17 12:22:12 2013
  kumar                               D        0  Thu Sep 12 17:27:38 2013 
  shiva                               D        0  Wed Sep 18 08:47:51 2013
  siva                                D        0  Wed Sep  4 18:44:45 2013
  Sundar                              D        0  Wed Sep 18 17:17:51 2013
  51203 blocks of size 2097152. 7692 blocks available
smb: \> 

Replace <hostname> with the hostname or IP address of the Samba server you want to connect to, <sharename> with the name of the shared directory you want to browse, and <username> with the Samba username for the system. Enter the correct password or press Enter if no password is required for the user.
If you see the smb:\> prompt, you have successfully logged in. Once you are logged in, type help for a list of commands. If you wish to browse the contents of your home directory, replace sharename with your username. If the -U switch is not used, the username of the current user is passed to the Samba server.
To exit smbclient, type exit at the smb:\> prompt.

Copy from widows shared file to Linux machine through Linux Terminal using smbclient:

smb: \siva\> get email1.png /home/itadmin/Documents/email1.png
getting file \siva\email1.png of size 292535 as /home/itadmin/Documents/email1.png (10202.8 KiloBytes/sec) (average 7935.5 KiloBytes/sec)
smb: \siva\> 


Copy from Linux machine file to Windows shared folder through Linux Terminal using smbclient:


smb: \siva\> put /home/itadmin/Documents/siva1.png siva1.pngputting file /home/itadmin/Documents/siva1.png as \siva\siva1.png (8162.2 kb/s) (average 8527.7 kb/s)
smb: \siva\> ls
 
.                                   D        0  Thu Sep 19 15:04:06 2013
  ..                                  D        0  Thu Sep 19 15:04:06 2013
   comics                              D        0  Wed Jul 10 16:49:33 2013
  Copy of icon_helpdesk.gif           A     1657  Wed Jul  3 13:45:49 2013
  Copy of livechat.png                A    17260  Wed Jul  3 16:37:07 2013
  Elvis-Testing.avep                  A  6991460  Wed Jul 10 13:01:52 2013
  Elvis-Testing.avep-Pages.zave       A  2238570  Wed Jul 10 14:19:06 2013
  Elvis-Testing.avep-Pages.zavem      A      341  Wed Jul 10 14:19:05 2013
  email1.png                          A   292535  Mon Jul  1 12:21:58 2013
  email2.png                          A     8622  Mon Jul  1 12:30:19 2013
  email35.png                         A     7618  Mon Jul  1 12:30:35 2013
  event.png                           A     1809  Wed Sep  4 18:44:07 2013
  forum.png                           A     1668  Sat Jun 29 15:11:03 2013
  icon_helpdesk.gif                   A     1657  Wed Jul  3 13:45:49 2013
  icon_helpdesk.png                   A     4505  Wed Jul  3 13:51:57 2013
  icon_helpdesk40.png                 A     4667  Wed Jul  3 13:52:16 2013
  KalleAnka&Co 1.0.2.ipa              A 32092113  Wed Jul 10 16:23:07 2013
  live100.png                         A     7373  Thu Jul  4 13:07:07 2013
  live150.png                         A     9953  Thu Jul  4 13:06:55 2013
  live80.png                          A     6503  Thu Jul  4 13:07:17 2013
  livechat.png                        A    17260  Wed Jul  3 16:37:07 2013
  logo.gif                            A     1843  Fri Aug 16 11:26:57 2013
  logo.png                            A     7289  Thu Aug  8 18:37:02 2013
  logos.gif                           A     1780  Fri Aug 16 11:33:40 2013
  magik_pinstyle_3                    D        0  Wed Jul 24 18:48:37 2013
  nforum.png                          A     5048  Sat Jun 29 15:44:46 2013
  photo                               D        0  Mon Aug 19 13:51:38 2013
  ricon.png                           A     1959  Sat Jun 29 15:32:37 2013
  scpsmb                              D        0  Wed Sep  4 18:45:39 2013
  sforum.png                          A     1668  Sat Jun 29 15:11:08 2013
  siva2.png                           A   292535  Thu Sep 19 15:03:04 2013
  siva1.png                           A   292535  Thu Sep 19 15:04:06 2013
  slide                               D        0  Wed Jul 31 16:07:19 2013
  sundarnew.png                       A     6925  Fri Aug  9 11:05:45 2013
  Thumbs.db                         AHS    82432  Mon Aug 19 13:51:40 2013
  webim                               D        0  Fri Aug  2 11:47:46 2013

        51203 blocks of size 2097152. 7692 blocks available

 



19.3.2. Mounting the Share

Sometimes it is useful to mount a Samba share to a directory so that the files in the directory can be treated as if they are part of the local file system.
To mount a Samba share to a directory, create create a directory to mount it to (if it does not already exist), and execute the following command as root:
 
 
mount -t cifs -o <username>,<password> //<servername>/<sharename> /mnt/point/


This command mounts <sharename> from <servername> in the local directory /mnt/point/. For more information about mounting a samba share, refer to man mount.cifs.

Wednesday, September 18, 2013

Zend framework 2.2 - ZfcUser module Configuration

Installing and configuring ZfcUser module and Doctrine2

Next task is to install ZfcUser module which will deal with User management in our Blog application and Doctrine2 which will be used as ORM (Object Relational Mapper). This is very easy, we just need to add some lines in our composer.json file and run update command. So, open your composer.json file (in project root folder) and make it look like this (I added other dependencies like Doctrine2 and Zend Developer tools, so we have everything we need to work with):
/composer.json
1
2
3
4
5
6
7
8
9
10
{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.5.3",
        "zendframework/zendframework": ">2.2.0rc1",
        "zendframework/zend-developer-tools": "dev-master",
        "zendframework/zftool": "dev-master",
        "zf-commons/zfc-user": "dev-master",
        "doctrine/doctrine-orm-module": "0.7.*",
        "zf-commons/zfc-user-doctrine-orm": "dev-master"
}
}
Save the file and run (from command line):



itadmin@itadmin-AcerPower-Series:/var/www/pod$ composer.phar update


itadmin@itadmin-AcerPower-Series:/var/www/pod$ composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)

  - Installing zf-commons/zfc-base (v0.1.2)
    Loading from cache

  - Installing zf-commons/zfc-user (dev-master fbbe5fd)
    Cloning fbbe5fdeabd9229bf7d1328358c2d95538a6081e

  - Installing doctrine/lexer (v1.0)
    Loading from cache

  - Installing doctrine/annotations (v1.1.2)
    Loading from cache

  - Installing doctrine/collections (v1.1)
    Loading from cache

  - Installing doctrine/cache (v1.1)
    Loading from cache

  - Installing doctrine/inflector (v1.0)
    Loading from cache

  - Installing doctrine/common (v2.4.1)
    Loading from cache

  - Installing doctrine/dbal (v2.4.0)
    Loading from cache

  - Installing symfony/console (v2.3.4)
    Loading from cache

  - Installing doctrine/orm (v2.4.0)
    Loading from cache

  - Installing doctrine/doctrine-module (0.7.2)
    Loading from cache

  - Installing doctrine/doctrine-orm-module (0.7.0)
    Loading from cache

  - Installing zf-commons/zfc-user-doctrine-orm (dev-master 08be7b2)
    Cloning 08be7b2a5e1ee31a3907582261c113531d2bf964


symfony/console suggests installing symfony/event-dispatcher ()
doctrine/orm suggests installing symfony/yaml (If you want to use YAML Metadata Mapping Driver)
doctrine/doctrine-module suggests installing doctrine/data-fixtures (Data Fixtures if you want to generate test data or bootstrap data for your deployments)
doctrine/doctrine-orm-module suggests installing doctrine/migrations (doctrine migrations if you want to keep your schema definitions versioned)
Writing lock file
Generating autoload files


Let me explain what just happened. Composer just installed all those modules into our project’s vendor folder. Well, for them to work with our application, we need to tell the application they exist, so it can use them properly.
Open /config/application.config.php and let us add those modules so we can use them:
/config/application.config.php
1
2
3
4
5
6
7
8
9
10
...
'modules' => array(
        'Application',
        'DoctrineModule',
        'DoctrineORMModule',
        'ZfcBase',
        'ZfcUser',
        'ZfcUserDoctrineORM',
    ),
...
If you point your browser to zf2blog.home/user/register and try to register, you will see a PDO exception that it can not connect to the database. Now comes the fun part …
First, create a new database for this and call it zf2blogtutorial (or whatever you want). After that, copy /config/autoload/local.php.dist to /config/autoload/local.php and add this to it:
/config/autoload/local.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// ...
'doctrine' => array(
        'connection' => array(
                'orm_default' => array(
                        'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                        'params' => array(
                                'host'     => 'localhost',
                                'port'     => '3306',
                                'user'     => '****',
                                'password' => '****',
                                'dbname'   => 'zf2blogtutorial',
                            )
                    )
            )
    ),
Replace username, password, dbname and other things according to your setup. If you try to register now, you will get this exception:
1
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'zf2blogtutorial.user' doesn't exist
Well, of course it doesn’t exist, as we didn’t create it. But, close your PHPMyAdmin, as you don’t need it.
Doctrine ORM module for Zend Framework 2 comes with handy tools which will help us with creating our application from top down. What does this mean?
Well, you first create an Entity and then generate a database schema. We did not create an Entity for ZfcUser, as it already has one included in it’s Doctrine module. So, let’s create the schema.
So, in your command line enter this in project root:
1
vendor/bin/doctrine-module orm:validate-schema
This just validates our database schema and will output something along this:
1
2
3
$ vendor/bin/doctrine-module orm:validate-schema
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.
To actually generate the schema, run this:
1
vendor/bin/doctrine-module orm:schema-tool:update --force
That’s it, you now have a user table in the database and a working Zend Framework2/Doctrine2 based user management… Go ahead and try to register now by going to zfblog.home/user/register.
It is working! Woot! Don’t worry about the looks of ZfcUser screens, that is because Skeleton application is using Twitter Bootstrap 3.0 and ZfcUser 2.*. We will fix that in next part.

Enabling ZendDeveloperTools

Let’s finish today’s session by enabling the handy Zend Developer tools. Open your /config/application.config.php and add Zend Developer Tools to the module list:
/config/application.config.php
1
2
3
4
5
6
7
8
9
'modules' => array(
        'ZendDeveloperTools',
        'Application',
        'DoctrineModule',
        'DoctrineORMModule',
        'ZfcBase',
        'ZfcUser',
        'ZfcUserDoctrineORM',
    ),
Now, copy /vendor/zendframework/zend-developer-tools/config/zenddevelopertools.local.php.dist to /config/autoload/zenddevelpertools.local.php
If everything is ok, you should see the toolbar on bottom of your application if you refresh the browser.

Tuesday, September 17, 2013

Using ZFTool.phar for Basic Project Management

Introduction

Welcome to another tutorial. Today, I will be giving you a walk through of zftool, which provides basic tooling support in Zend Framework 2. If you’re new to Zend Framework, or have been reading the introductory series here, it can come in quite handy.
But unlike other frameworks, such as Yii (through yiic) and Symfony (via the Command Line tool), the tooling support in Zend Framework 2 is rather light on.
These respective tools provide rather robust support for automatically generating models from database connections, checking logs and a host of other much required functionality.
I understand from some tweets with Enrico Zimuel new additions are planned for zftool. But for right now, Zend Framework is definitely the junior. However, that aside, I like to take the adage of a glass half full and see zftool as a good start. Today we’re going to use it to carry out the following tasks:
  1. Create a basic ZF2 project
  2. Create several modules
  3. Creating an autoloader classmap
  4. Checking if there are any issues
By the end of today’s tutorial, you will have a good understanding of how to get started with it and to be able to use it in your projects. Firstly, let’s install zftool and get started.
Note for Windows Users This tutorial is run under Ubuntu Linux. However, with only minor changes, you can run it in your version of Windows as well.

Installation

There are a number of ways in which zftool can be installed, including using Composer and downloading the Phar tool.
During the research for this article, I tried to install it via Composer, but continuously met with permission related errors. As a result, I’ve chosen to focus on the Phar tool approach, which works, almost, seamlessly.
If you’d like to go down the Composer route, run the following command in your Terminal or console and you’ll have it available.

$ composer require zendframework/zftool:dev-master
 
Otherwise, download the phar file. Once it’s downloaded, run the following commands. These make it accessible universally on your system:


sudo cp -v zftool.phar /usr/local/bin/
cd /usr/local/bin/
sudo ln -s zftool.phar zftool
sudo chmod +x zftool.phar 
 
If you’re not familiar with the Linux command line, what we’ve done here is to copy zftool.phar to one of the directories automatically in a users PATH.
Then we’ve created a symlink to it, giving it a simpler name and finally set the executable bit on it – now it’s ready to run.

Running the Phar Tool

Now that we have the Phar file available, let’s have a look at the options available. Running the following command will display a help screen, showing all of the options supported:
zftool -v
ZFTool - Zend Framework 2 command line Tool

--------------------------------------------------------------------------------------------------------------------------------------------------------
ZFTool
--------------------------------------------------------------------------------------------------------------------------------------------------------

Basic information:
  zftool modules [list]         show loaded modules                                                                            
  zftool version | --version    display current Zend Framework version                                                         

Diagnostics
  zftool diag [options] [module name]    run diagnostics                                                                       

  [module name]    (Optional) name of module to test                                                                                                 
  -v --verbose     Display detailed information.                                                                                                     
  -b --break       Stop testing on first failure                                                                                                     
  -q --quiet       Do not display any output unless an error occurs.                                                                                 
  --debug          Display raw debug info from tests.                                                                                                

Application configuration:
  zftool config list                  list all configuration options                                                           
  zftool config get <name>            display a single config value, i.e. "config get db.host"                                 
  zftool config set <name> <value>    set a single config value (use only to change scalar values)                             

Project creation:
  zftool create project <path>    create a skeleton application                                                                

  <path>    The path of the project to be created                                                                                                    

Module creation:
  zftool create module <name> [<path>]    create a module                                                                      

  <name>    The name of the module to be created                                                                                                     
  <path>    The root path of a ZF2 application where to create the module                                                                            

Controller creation:
  zftool create controller <name> <module> [<path>]    create a controller in module                                           

  <name>      The name of the controller to be created                                                                                               
  <module>    The module in which the controller should be created                                                                                   
  <path>      The root path of a ZF2 application where to create the controller                                                                      

Action creation:
  zftool create action <name> <controllerName> <module> [<path>]    create an action in a controller                           

  <name>              The name of the action to be created                                                                                           
  <controllerName>    The name of the controller in which the action should be created                                                               
  <module>            The module containing the controller                                                                                           
  <path>              The root path of a ZF2 application where to create the action                                                                  

Classmap generator:
  zftool classmap generate <directory> <classmap file> [--append|-a] [--overwrite|-w]                                          

  <directory>         The directory to scan for PHP classes (use "." to use current directory)                                                       
  <classmap file>     File name for generated class map file  or - for standard output. If not supplied, defaults to autoload_classmap.php inside    
                      <directory>.                                                                                                                   
  --append | -a       Append to classmap file if it exists                                                                                           
  --overwrite | -w    Whether or not to overwrite existing classmap file                                                                             

Zend Framework 2 installation:
  zftool install zf <path> [<version>]                                                                                         

  <path>       The directory where to install the ZF2 library                                                                                        
  <version>    The version to install, if not specified uses the last available                                                                      

Reason for failure: Invalid arguments or no arguments provided


Creating a Project

Ok, with the tool ready to go, let’s set about using some of it’s functionality to creating and managing a Zend Framework 2 project, as outlined above.

Create the Project

Firstly, we’ll create a raw project, called ‘simple project’. To do so, run the following command:

$ php zftool.phar create project ./simpleproject

This will create the core project files in a directory in the current directory, called ‘simpleproject’. It will give you output similar to that below:
 
ZF2 skeleton application installed in ./simpleproject.
In order to execute the skeleton application you need to install the ZF2 library.
Execute: "composer.phar install" in ./simpleproject
For more info in ./simpleproject/README.md 
 
Assuming there were no permission issues, the project directory should look as follows:

$ ls -l ./simpleproject/
-rw-rw-r-- 1 maltblue maltblue    342 Jun 12 06:34 composer.json
-rwxr-xr-x 1 maltblue maltblue 709565 Jun 12 06:34 composer.phar
drwxrwxr-x 3 maltblue maltblue   4096 Jun 12 06:34 config
drwxrwxr-x 3 maltblue maltblue   4096 Jun 12 06:34 data
-rw-rw-r-- 1 maltblue maltblue   1807 Jun 12 06:34 init_autoloader.php
-rw-rw-r-- 1 maltblue maltblue   1548 Jun 12 06:34 LICENSE.txt
drwxrwxr-x 3 maltblue maltblue   4096 Jun 12 06:34 module
drwxrwxr-x 5 maltblue maltblue   4096 Jun 12 06:34 public
-rw-rw-r-- 1 maltblue maltblue   1759 Jun 12 06:34 README.md
drwxrwxr-x 3 maltblue maltblue   4096 Jun 12 06:34 vendor

The Generated composer.json File

Looking in the project directory, we see a new composer.json file, which has the basic configuration and requirements for a Zend Framework 2 project. If you’d like to go further, feel free to alter it as suits your needs, running composer update afterwards.
 
 
{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.5.3",
        "zendframework/zendframework": ">2.2.0rc1",
        "zendframework/zend-developer-tools": "dev-master",
        "zendframework/zftool": "dev-master",
    
    }
}

Installing Zend Framework 2 in the Project (With Composer)

With the basic files in place, unless you have the Zend Framework libraries on your path, the application won’t run. So, in the project directory, run composer.phar install to bring in the required libraries and dependencies.
The output will look similar to that below. I’ve trimmed it for sakes of readability.
 
$ composer.phar install  (or) $ php composer.phar install
 
Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing zendframework/zendframework (2.2.0)
    Downloading: 100%             

Writing lock file
Generating autoload files

Creating a Module

Now let’s create a module which doesn’t already exist; we’ll call it Generic. As before, we create the module via the command below:

zftool.phar create module Generic

You should see output similar to that below, indicating there were no problems.
 
The module Generic has been created

Looking in the Generic module directory, we see the following structure:
 
$ ls -l module/Generic/
total 16
drwxrwxr-x 2 maltblue maltblue 4096 Jun 12 06:47 config
-rw-rw-r-- 1 maltblue maltblue  437 Jun 12 06:47 Module.php
drwxrwxr-x 3 maltblue maltblue 4096 Jun 12 06:47 src
drwxrwxr-x 2 maltblue maltblue 4096 Jun 12 06:47 view


Under config is a module.config.php file. So, we now have the basic structure of a ZF2 module.

Viewing a List of Modules

But what if we want to see the list of modules? Well, here’s where I hit an issue. I believe the following command will show us that list.

$ php zftool.phar modules (or) $zftool modules

But no matter what I tried, it always resulted in the following error:
No modules installed. Are you in the root folder of a ZF2 application?
At this stage, I’m not sure if it’s a bug or a user (me) problem. However, as I get more information, I’ll update the post about this issue.

Classmap Generation

Ok, we’re just about done. If you’re familiar with Zend Framework 2, you’ll know that performance can be increased through a classmap file.
A class map file stores a map of files which the application may require, saving it from performing a file location resolution. Effectively, it’s a class file location cache.
Let’s assume we have a series of classes in the module directory. Let’s create a classmap file for it. To do so, we run the following command:

$ zftool classmap generate module/ autoload_classmap.php
 
This looks for all class files in the module directory and then writes it out to autoadclassmap.php in the current directory. It will have output similar to that below:
 
Creating classmap file for library in /home/parallels/zftool/vendor/simpleproject/module
Scanning for files containing PHP classes .... DONE
Found 4 PHP classes
Creating classmap code ... DONE

Writing classmap to autoload_classmap.php...  DONE
Wrote classmap to /home/parallels/zftool/vendor/simpleproject/autoload_classmap.php

The Generated Classmap File

If you’ve not seen a classmap file before, here’s what the one we just created looks like (formatted for better readability):
    $ cat autoload_classmap.php 
    <?php
    // Generated by Zend Framework 2
    return array(
        'Generic\Module' => DIR . '/module/Generic/Module.php',
        'Application\Controller\IndexController' => DIR . 
'/module/Application/src/Application/Controller/IndexController.php',
        'Application\Module' => DIR . '/module/Application/Module.php',
        'Users\Module' => DIR . '/module/Users/Module.php',

Running Diagnostics

Now on to the last command we’re going to run, module diagnostics. I’m going to run diagnostics on the new, Generic, module we’ve created in this tutorial. From the project root, run the following command:
 
$ zftool diag --debug Generic

This will run diagnostics, showing debug information. In this case, just re-iterating the running version of PHP.


itadmin@itadmin-AcerPower-Series:/var/www/simpleproject$ zftool diag --debug Generic
Starting diagnostics:
  OK   ZF: PHP Version: Current PHP version is 5.5.3-1+debphp.org~precise+2
       -------------------------------------------------------------------------------------------------------------------------------------------------
       '5.5.3-1+debphp.org~precise+2'
       -------------------------------------------------------------------------------------------------------------------------------------------------

OK (1 diagnostic tests)                                                                                                                                

itadmin@itadmin-AcerPower-Series:/var/www/simpleproject$                                                                                                      

Verbose Information

Running it again, with the verbose flag set, show’s approximately the same information, just less detailed. We can see here there were no issues with the module. So there was nothing to report.
 
itadmin@itadmin-AcerPower-Series:/var/www/simpleproject$ zftool diag --debug Application
Starting diagnostics:
  OK   ZF: PHP Version: Current PHP version is 5.5.3-1+debphp.org~precise+2
       -------------------------------------------------------------------------------------------------------------------------------------------------
       '5.5.3-1+debphp.org~precise+2'
       -------------------------------------------------------------------------------------------------------------------------------------------------

OK (1 diagnostic tests)                                                                                                                                

itadmin@itadmin-AcerPower-Series:/var/www/simpleproject$                                                                                                      

I must admit I’m not quite sure of the intent of the diagnostic tool. I’ve renamed Module.php in Generic, renamed the Generic module directory, yet still the tool reports everything is ok.
I’ll be doing so more research into this and updating the article with what is found.