Download the PHP package edgaralexanderfr/php-espresso without Composer

On this page you can find all versions of the php package edgaralexanderfr/php-espresso. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-espresso

PHP Espresso Framework

PHP Espresso Example GIF

View last release PHP 8.0.0 Experimental Sockets Composer

PHP Espresso is a small PHP Framework I created to develop runtime web servers for PHP running CLI programs and scripts. Very similar to frameworks like Express for NodeJS, Gorilla Mux for Golang, etc.

IMPORTANT NOTE: This is just a proof of concept to test the reliability of a runtime web server for PHP, its use and implementation is discouraged for production-level projects as it's an experimental framework for learning purposes.

PHP was designed to be a Single-Threaded Non-Asynchronous programming language, hence, the implementation of these type of web servers is very difficult as there will be always blocking processes for each request, hence, this server/framework is non-scalable.

Table of contents 📖
  1. Requirements
  2. Installation
  3. Usage

Requirements

  1. PHP 8.0.0 or major
  2. Have PHP sockets module installed and enabled
  3. Composer
  4. Have a initted Composer project

Installation

Install PHP Espresso via Composer:

Usage

Creating a basic web server

Create a server.php file inside your project with the following program:

Run the server:

Visit http://localhost or execute:

And voila! 🎉

Serving a basic static HTML Page

Visit http://localhost/php-espresso-page in your browser.

Create a POST request:

Execute a POST request:

Complete Rest API CRUD example:

Create a couple of users:

Retrieve all created users:

Retrieve user with id 2:

Update user with id 1:

Delete user with id 2:

Defining middlewares

PHP Espresso supports global and route middlewares. You can assign as much middlewares to a single route as you want.

To do so, you can create a new middlewares.php file and add the following code:

If you run:

And do:

Or:

You will get the following message:

If you kill the previous server with CTRL+C and then run:

You will be able to retrieve the users list now, e.g:

To create a new user you need to be authenticated, to do so, assign an encoded Bearer Token using base64 to a variable and then pass the Authorization Header to curl command:

Asynchronous programming

It's still possible to do asynchronous programming with PHP Espresso by creating an asynchronous server and using the async and $next functions and callables:

The async function initiates an Event Looper inside of the listen method when running in async mode by setting $server->async(true);.

async may return a boolean value (false) when the async call is not done yet and returns true or nothing when it's finished.

In this example, the async call inside of the read_file function will return false as long as the requested file is not completed yet, this by reading $bytes as a step for each chunk read through every call inside the Event Loop as an asynchronous process.

Once the whole file is read, the $callable callback will be called, passing in the content of the file on the async call by returning nothing at the very end of the function.

If you execute:

The smaller file request will respond earlier than the larger file request despite of being executed right at the same time.

This could be a way to implement asynchronous programs and libraries for streaming, networking, databases, files, I/O operations, etc, although it's not perfect, it would require a vast work to implement lots of PHP libraries that were designed initially to be Single-Threaded and Synchronous.

Maybe the future of PHP is promising for this purpose with the introduction of tools like Fibers and stuff, but yet, we will see how it goes. 🙂🐘


All versions of php-espresso with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package edgaralexanderfr/php-espresso contains the following files

Loading the files please wait ....