Olanrewaju 2015
Olanrewaju 2015
40.1 Introduction
The rapid development of internet for web based application indicates a higher
demand of reliability, scalability, security and maintainability of coding method-
ology. PHP, a scripting tool for web that enable dynamic interactive web devel-
opment such intuitive, compiled fast, cross platform, open source, flexibility as
well as required minimal setup [1]. This became one of the important web
development language thus, PHP is one of the most powerful programming lan-
guage in the web world. Several developers choose to deploy application based on
PHP putting all the issues such as data access, business logic, and data repre-
sentation layer together [2]. This in turn create development problems especially
for big projects. To solve this problem, MVC design pattern brings an effective
ways to separate code in layers from each other based on each layer activities.
MVC design pattern is a proven effective way to develop application such as
CakePHP, CodeIgniter, Laravel, Symfony. The main methods of MVC to spilt an
application into separate layer that can work separately and produce same result.
The advantage of using MVC pattern are:
• Standard, consistency and predictability
• Software components or building-blocks so that developers can share and reuse
code [3]
• A model or standard architecture that allows easy visualization of how the
entire system works [4]
• Reusable and thoroughly tested code in the libraries, classes and functions [5].
• Well-structured code using architectural pattern [6].
• Security, interoperability and Maintenance.
Although MVC based framework (CakePHP, Laravel, CodeIgniter) has number
of advantages [7], however, selecting of best PHP framework is still a concern.
This is because all of the framework does not cover all aspect of web applications.
This study evaluate most famous PHP frameworks based on MVC design model
and it performance as well as proposed the best efficient PHP MVC framework for
future web development.
The operation of Model View Controller (MVC) method is to spilt or separate the
different parts of code into layers such as view, data access, controlling user’s
requests and forward request to relevant layers [8].
The MVC pattern’s title is a collation of three core parts: Model, View, and
Controller. A visual representation of a complete and correct MVC pattern looks
like the following in Fig. 40.1.
40 An Empirical Study of the Evolution of PHP MVC Framework 401
MODEL
MA
NIP
TES UL
AT
DA ES
UP
VIEW CONTROLLER
SE
ES
ES
US
USER
Figure 40.1 shows the pattern and interaction with the user and the application
itself. It is a single flow layout of data, how it’s passed between each component,
and finally how the relationship between each component works.
40.2.1 Model
The Model is the name given to the permanent storage of the data used in the
overall design. It must allow access for the data to be viewed, or collected and
written to, and is the bridge between the View component and the Controller
component in the overall pattern [9].
One important aspect of the Model is that it’s technically ‘‘blind’’—by this, the
model has no connection or knowledge of what happens to the data when it is
passed to the View or Controller components [10]. It neither calls nor seeks a
response from the other parts of the component; its main purpose is to process data
into its permanent storage, seek and prepare data to be passed along to the other
parts.
The Model cannot simply be assumed as a database toolkit only, or a gateway
to another system which handles the data process [11]. The Model represents a
gatekeeper to the data itself, asking no questions but accept all requests which
comes its way. Often this most complex part of the MVC system, the Model
component is also the pinnacle of the whole system since without it there will be
no connection between the Controller and the View.
402 R.F. Olanrewaju et al.
40.2.2 View
The View is a module where data, requested from the Model is viewed and its final
output is determined. Traditionally in web application use MVC for development,
the View is the part of the system where the HTML is generated and displayed.
The View also ignites reactions from the user, who then goes on to interact with
the Controller. The basic example of this is a button generated by the View, which
a user clicks and triggers an action in the Controller.
There are some misconceptions held about View components, particularly by web
developers using the MVC pattern to build their application. For example, many
mistaken the View as having no connection whatsoever to the Model and that all
of the data displayed by the View is passed from the Controller. In reality, this
flow disregards the theory behind the MVC pattern completely. Fabio Cevasco’s
article, The CakePHP Framework: Your First Bite [1] demonstrates this confused
approach to MVC in the CakePHP framework.
In order to correctly apply the MVC architecture, there must be no interaction
between models and views: all the logic is handled by controllers [13]. Further-
more, the description of Views as a template file is inaccurate. The View is really
much more than just a template, the modern MVC inspired frameworks have
bastardised the view almost to the point that no one really cares whether or not a
framework actually adheres to the correct MVC pattern or not. It’s also important
to mention that the View part is never given data by the Controller. There is no
direct relationship between the View and the Controller without the Model in
between them.
40.2.3 Controller
The third component of the triad is the Controller. Its job is to handle data the user
submits as well as update the Model accordingly. The Controller can be summed
up as a collector of information, which then passes it on to the Model to be
organized for storage, and does not contain any logic other than collecting user
input [9]. The Controller is also only connected to a single View and to a single
Model, making it a one way data flow system, with handshakes and signoffs at
each point of data exchange. Controller is only given tasks to perform when the
user interacts with the View first, and that each Controller function is a trigger, set
off by the user’s interaction with the View [14]. The most common mistake made
by developers is confusing the Controller as a gateway, and ultimately assigning it
functions and responsibilities that the View should do (this is normally a result
of the same developer confusing the View component as a template).
40 An Empirical Study of the Evolution of PHP MVC Framework 403
Additionally, it’s a common mistake to assign the Controller functions that gives it
the sole responsibility of crunching, passing, and processing data from the Model
to the View. Nonetheless, the MVC pattern relationship should be kept between
the Model and the View.
40.3.1 CodeIgniter
40.3.2 CakePHP
40.3.3 Symfony
40.3.4 Laravel
Laravel is a free, open source PHP web application framework, designed for the
development of MVC web applications. Laravel is released under the MIT license,
with its source code hosted on GitHub.
The key design points of Laravel are:
• Bundles provide Laravel with a modular packaging system, and numerous
bundled features are already available for easy addition to applications.
• Eloquent ORM is an advanced PHP implementation of the active record pat-
tern, providing internal methods for enforcing constraints to the relationships
between database objects [18].
• Application logic is part of developed applications, either by using controllers,
or as part of route declarations. Syntax used for definitions is similar to the one
used by Sinatra framework.
• Reverse routing defines a relationship between links and routes, making it
possible for later changes to routes to be automatically propagated into relevant
links. When links are created by using names of existing routes, appropriate
URIs are automatically created by Laravel [19].
• Restful controllers provide an optional way for separating the logic behind
serving HTTP GET and POST requests.
• Class auto loading provides automated loading of PHP classes, without the
need for manual maintenance of inclusion paths. On-demand loading prevents
loading of unnecessary components; loaded are only those components which
are actually used [20].
• View composers are logical code units that can be executed when a view is
loaded.
• Migrations provide a version control system for database schemas, making it
possible to associate changes in the application’s code base and required changes
in the database layout, easing deployment and updating of applications [21].
• Unit testing plays an important role in Laravel, which itself has a large number
of tests for detecting and preventing regressions. Unit tests can be run through
the artisan command-line utility [22].
• Automatic pagination simplifies the task of implementing pagination, replacing
the usual manual implementation approaches with automated methods inte-
grated into Laravel [23].
40.4 Benchmarking
memory usage, number of function calls and number of files required on each of
the MVC. To evaluate these four frameworks, web design which contains ‘‘hello
word’’ was carried out on apache (ab –c 200 –n 50,000), below are results of each
evaluation criteria.
This benchmarking is based on apache (ab –c 200 –n 50,000). Figure 40.2 shows
the performance comparison among four MVC: CI, CakePHP symphony and
Laravel. It can be seen that Laravel outperforms other MVC in terms of request
person. It was able to handle 3,000 request per second compare to others. In this
case, bigger output indicates perfect result hence, it denotes best performance.
The system average load is measure in relation to time. that is, in 1 min when
Apache Benchmark is complete, the smaller is better in the condition of (ab –c 200
–n 50,000). Figure40.3 shows the comparison of the four MVC in terms of system
load within 1 min. In this graph, Laravel contain lowest times (0.98) where
CakePHP contain maximum load time 5.1 per minute to load system. Based on
average time, lowest average time is better to run MVC application.
This benchmarking checks how much memory is used in a one word ‘hello world’
page display. The smaller number of KB the better the memory usage. Figure 40.4
indicated that Laravel is about 518 KB compare to CI which is which 725 Kb
follow by symphony with memory usage of about 1,711 then CakePHP with
2,824 KB. Hence, it can be concluded that Laravel memory usage is efficient.
The time of page request to response from framework is one of the most important
criteria to evaluate MVC performance. It is calculated in millisecond. The lower
number of millisecond calculated the better performance. Figure 40.5 depicts the
result of all the four MVC used. Among all, Laravel came out to be with the least
response time, 4.46 ms compare to CI with 7.2 followed by symphony with 12
then CakePHP with about 14 ms.
40 An Empirical Study of the Evolution of PHP MVC Framework 407
This test checks how many functions are calling for one ‘‘hello world’’ pages in
terms of Facebook XHProf [24]. Here smaller number of functions is most
effective for PHP framework evaluation. It can be seen from Fig. 40.7, Laravel
outperforms other MVC framework with the minimal number of function calls
with 238 calls compare to CakePHP 834 and others (Fig. 40.6).
The number of files included or required in one ‘hello world’ page. Less amount of
required files represent that such framework will be loaded first in-terms of file
408 R.F. Olanrewaju et al.
7.52% Yii
Cake PHP
4.51% Zend
16.73%
7.62% Pear
Aura
7.62%
10.62% Others
40.6 Conclusion
An empirical study on major MVC pattern for PHP framework has been evaluated
in this paper.
The results obtained from evaluating the four frameworks: CodeIgniter (CI),
Symfony, CakePHP and Laravel using criteria such as request per second, system
load average, memory usage, number of function calls and number of files required
as well as available facilities in each framework. It shows that the Laravel out-
performs other MVC framework. A request per second of as high as 3,000 was
recorded for Laravel compare to others like CakePHP with as low as 750 request
per second. The results obtained for all other parameters such has storage, function
calls, number of files, response time etc. indicated that Laravel has huge flexibility
410 R.F. Olanrewaju et al.
References
1. Bergmann, S., Kniesel, G.: GAP: generic aspects for PHP. In: Proceedings of EWAS’06
(2006)
2. Bakken, S.S., Aublach, A., Schmid, E., et al.: PHP manual (The PHP Documentation Group).
https://php.net/manual/en/index.php, Accessed 10 March 2014
3. Nakajima, S., Hokamura, K., Ubayashi, N.: Aspect-oriented development of PHP-based web
applications, 34th annual IEEE computer software and applications conference workshops
(2010)
4. Veglis, A., Leclercq, M., Quema, V.: PHP and SQL made simple distributed systems online,
Volume 6 Issue 8, August 2005, Page 4
5. http://webcoderpro.com/blog/top-6-most-popular-php-frameworks-of-2013/. Accessed 21
Jan 2014
6. http://www.catswhocode.com/blog/top-10-php-frameworks-for-2014. Accessed 23 Jan 2014
7. http://www.sitepoint.com/best-php-frameworks-2014/. Accessed 20 Jan 2014
8. Ricca, F., Tonella, P.: Analysis and testing of web applications. In: Proceedings of 23rd
ICSE, pp. 25–34 (2001)
9. http://www.tonymarston.net/php-mysql/model-view-controller.html. Accessed 13 Dec 2013
10. Cui, W., Huang, L., Liang, L.J., Li, J.: The research of PHP development framework based on
MVC pattern, 4th international conference on computer sciences and convergence
information technology (2009)
11. http://www.sitepoint.com/the-mvc-pattern-and-php-1/. Accessed 15 Jan 2014
12. http://www.sitepoint.com/application-development-cakephp/. Accessed 17 Jan 2014
13. Enderlin, I., Giorgetti, A., Bouquet, F.: A constraint solver for PHP array, 6th international
conference on software testing, verification and validation workshops (2013)
14. http://matrix.include-once.org/framework/simplese. Accessed 19 Jan 2014
15. http://en.wikipedia.org/wiki/CodeIgniter. Accessed 10 Mar 2014
16. http://en.wikipedia.org/wiki/MIT_License. Accessed 28 Feb 2014
17. http://en.wikipedia.org/wiki/Symfony. Accessed 11 Mar 2014
18. http://www.developed.be/2013/07/16/php-frameworks-which-to-choose/. Accessed 16 Jan
2014
19. http://brianretterer.com/why-laravel-is-the-best-php-framework/. Accessed 15 Jan 2014
20. http://www.ruilog.com/blog/view/b6f0e42cf705.html. Accessed 8 Mar 2014
21. http://www.webdesignermag.co.uk/features/laravel-a-modern-php-framework/. Accessed 17
Jan 2014
22. Merlo, E., Letarte, D., Antoniol, G.: Automated protection of PHP applications against SQL-
injection attacks, 11th European conference on software maintenance and reengineering
(2007)
23. http://en.wikipedia.org/wiki/Laravel_(framework). Accessed 9 Mar 2014
24. http://www.php.net/manual/en/intro.xhprof.php. Accessed 10 Mar 2014