programming development, we generally discover approaches to perform quick application development with worldwide code shows by observing standard security and development rules. In spite of the fact that we have a few PHP structures for development, shouldn’t something be said about an application that you need to create in a day or a few hours?
The appropriate response lies in small scale systems.
What are Micro-Frameworks?
Small scale framework is a term utilized for web application frameworks, generally got from full-stack frameworks. They are useful in making applications which send and get HTTP demands, steering HTTP solicitation to the particular regulator, and dispatch and return the regulator reaction. They are regularly used to make API applications for different administrations or instruments.
There are heaps of Micro frameworks got from various frameworks. We will talk about them independently and how you can undoubtedly introduce them on cloud workers.
Here is the rundown of top PHP Micro-frameworks we are going to cover in this article:
- Silex
- Thin
- Lumen
- Slug PHP
- Limonade
- Wave Framework
To introduce Restful small scale frameworks on cloud workers, I have made a PHP application worker on Cloudways by propelling a Digital sea worker.
Cloudways is also providing a pre-installed Composer so we don’t need to install it. After launching the application move to your public_html folder and then run the installation commands.
Silex Microframework
Silex is a PHP miniaturized scale structure worked with Symfony parts and Pimple. Silex can be utilized to make single-page applications. Silex has an expansion framework based around the Pimple miniaturized scale administration compartment that makes it significantly simpler to tie in outsider libraries. It utilizes the Symfony HTTPKernel to ask for and react to HTTP demands.
Installation
1
|
composer require silex/silex “~2.0”
|
Code Example
Simply define a controller and map them to routes
1
2
3
4
5
6
7
8
9
|
require_once __DIR__.‘/../vendor/autoload.php’;
$app = new SilexApplication();
$app->get(‘/hello/{name}’, function($name) use($app) {
return ‘Hello ‘.$app->escape($name);
});
$app->run();
|
Slim Framework
Thin is a PHP miniaturized scale framework that encourages you rapidly compose straightforward yet amazing web applications and APIs. At its center, Slim is a dispatcher that gets a HTTP demand, conjures a suitable callback schedule, and returns a HTTP reaction. A thin application contains various courses that react to explicit HTTP demands. To begin, you first start and design the thin application at that point characterize regulator courses and afterward run the application.
Installation
1
|
composer require slim/slim “^3.0”
|
Code Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<?php
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpMessageResponseInterface as Response;
require ‘vendor/autoload.php’;
$app = new SlimApp();
$app->get(‘/hello/{name}’, function (Request $request, Response $response) {
$name = $request->getAttribute(‘name’);
$response->getBody()->write(“Hello, $name”);
return $response;
});
$app->run();
|
You might be interested: Creating a Simple REST API With Slim Framework
Lumen
Lumen is a new project from Laravel creator Taylor Otwell. Lumen depends on the laravel base and working with its components but lumen was built for microservices. Lumen is for projects and components that can benefit from the convenience and power of Laravel, but can afford to sacrifice some configurability and flexibility in exchange for a speed boost.
Installation
1
2
3
4
5
|
//in project folder
composer require “laravel/lumen-installer”
//for global installation
composer global require “laravel/lumen-installer”
|
After installation you need to set the path of lumen by running the command in SSH.
1
|
export PATH=“$PATH:$HOME/vendor/bin”
|
Code Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<?php
/**
* Reimagine what you expect…
*/
$app->get(‘/’, function() {
return [‘version’ => ‘5.3’]
});
/**
* From your microframework…
*/
$app->post(‘framework/{id}’, function($framework) {
$this->dispatch(new Energy($framework));
});
$app->get(‘api/users/{id}’, function($id) {
//some code
});
|
You might be interested: Creating REST API With Lumen
Bullet PHP
Bullet PHP is a useful microframework used to create REST API that automatically confirms the HTTP request. Bullet is resource and URI-oriented and comes pre-loaded with powerful HTTP features like content-negotiation and caching. Apps in Bullet PHP are built around HTTP URI and defined paths. It handles one code segment at a time and executes the callback for that segment.
Installation
1
|
composer require vlucas/bullet PHP
|
Code Example
1
2
3
4
5
6
7
8
9
|
$app = new BulletApp();
$app->path(‘foo’, function($request) use($app) {
return “foo”;
});
$app->path(‘bar’, function($request) use($app) {
$foo = $app->run(‘GET’, ‘foo’); // $foo is now a `BulletResponse` instance
return $foo->content() . “bar”;
});
echo $app->run(‘GET’, ‘bar’); // echos ‘foobar’ with a 200 OK status
|
Limonade
Limonade is a PHP microframework for rapid web development and prototyping.It’s inspired by frameworks like Sinatra or Camping in Ruby, or Orbit in Lua. It aims to be simple, lightweight and extremely flexible.
Installation
1
|
$ wget https://github.com/sofadesign/limonade/archive/master.zip
|
Unzip folder in SSH
1
|
$ unzip master.zip
|
Example Code
1
2
3
4
5
6
7
|
require_once ‘vendors/limonade.php’;
dispatch(‘/’, ‘hello’);
function hello()
{
return ‘Hello world!’;
}
run();
|
Wave Framework
Built loosely on model-view-control architecture and factory method design pattern, Wave is made for web services, websites and info-systems. This microframework is built around native API architecture, caching and smart image and resource management. Wave is a compact framework that does not include optional libraries, has a very small footprint and is developed keeping lightweight speed and optimizations in mind.
Wave comes by default with a view controller and a gateway intended for website functionality with clean URLs that also incorporates a front-end JavaScript controller.
Installation
1
|
$wget https://github.com/kristovaher/Wave-Framework/archive/master.zip
|
Unzip folder in SSH
1
|
$ unzip master.zip
|
Code Example
1
2
3
4
5
6
|
$apiResult=$this->api(‘user-login’,array(‘username’=>‘bluth’,‘password’=>‘123456’));
if($this->checkTrueFalse($apiResult)){
// API call was successful
} else {
// API call failed, either because of an error or failure response-code
}
|
Final Words
Since you are familiar with the establishment of a portion of the top PHP miniaturized scale structures on a Cloud have, there’s no reason for managing the issues of shared facilitating. There are a couple of more systems, similar to Flight and Recess PHP, and so on., that you can likewise take a stab at the Cloudways PHP Stack.
In the event that you have any inquiries about the article or any inquiries by and large, utilize the remark segment beneath!
Make PHP sites without the concern of worker the executives.
Convey your PHP application on streamlined PHP facilitating workers.
About Shahroze Nawaz
Shahroze is a PHP Community Manager at Cloudways – A Managed PHP Hosting Platform. He’s always in search of new frameworks and methods to implement them. Besides his coding life, he loves movies and playing soccer with friends. You can email him at shahroze.nawaz@cloudways.com