PHPackages                             desilva/microserve - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. desilva/microserve

ActiveLibrary[API Development](/categories/api)

desilva/microserve
==================

Lightweight API for creating PHP application servers

v2.0.0(1y ago)2163.4k↑212.5%1MITPHPPHP ^8.0

Since Jun 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/caendesilva/microserve)[ Packagist](https://packagist.org/packages/desilva/microserve)[ Docs](https://github.com/caendesilva/microserve)[ Fund](https://www.buymeacoffee.com/caen)[ RSS](/packages/desilva-microserve/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (2)Versions (9)Used By (1)

Microserve - API for creating PHP application servers.
======================================================

[](#microserve---api-for-creating-php-application-servers)

### Minimal. Agnostic. Zero dependencies.

[](#minimal-agnostic-zero-dependencies)

About
-----

[](#about)

[![](https://camo.githubusercontent.com/f42c9931dd2818e239dfef4ab1abdd67f9d307757b4bc63eacfc36ad331e44be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646573696c76612f6d6963726f7365727665)](https://camo.githubusercontent.com/f42c9931dd2818e239dfef4ab1abdd67f9d307757b4bc63eacfc36ad331e44be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646573696c76612f6d6963726f7365727665)[![](https://camo.githubusercontent.com/59ea779f6eae6f7214af922fd8c3ba08de1a228d6530df5cad06f6e34ca02644/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646573696c76612f6d6963726f7365727665)](https://camo.githubusercontent.com/59ea779f6eae6f7214af922fd8c3ba08de1a228d6530df5cad06f6e34ca02644/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646573696c76612f6d6963726f7365727665)

This package provides a framework for creating application servers and is intended to be used as a starting point for other packages. Think if this as a layer between the low-level PHP server implementations and your higher level application logic, allowing you to interact with the requests and responses in an abstracted object-oriented way that you may be used to. The name comes from it being based on [Pikoserve](https://github.com/caendesilva/pikoserve).

Installation
------------

[](#installation)

Install the package using Composer ([desilva/microserve](https://packagist.org/packages/desilva/microserve))

```
composer require desilva/microserve
```

Usage
-----

[](#usage)

Please see the example project in the [`docs`](docs/installation.md) directory.

This project is also used for the server core of the [HydePHP Realtime Compiler (V2.0)](https://github.com/hydephp/realtime-compiler), I recommend you take a look at the implementation there as well.

### High level overview

[](#high-level-overview)

You'll need to take care of bootstrapping yourself as each use case is different.

In general, you'll want to route all requests to a single entry point, which should be an extension of the HttpKernelInterface. This is where you would bind a router or similar to handle the requests.

#### General implementation

[](#general-implementation)

The recommended way to implement a server is to route all HTTP requests to the `server.php` script. This script should register the Composer autoloader, run the `bootstrap.php` script, then finally create a new `Application` instance to capture and handle the incoming HTTP request.

Here's an example of a `server.php` script:

```
require_once 'vendor/autoload.php';

$app = \Desilva\Microserve\Microserve::boot(\App\Http\MyHttpKernel::class);
$app->handle(); // Process the request to create and send the response
```

The `boot()` method will construct your Kernel, and then return an `Application` instance containing it.

We then call the `handle()` method which will inject a `Request` object, then call the Kernel handle method which returns a `Response` object which is used to send the HTTP response to the client.

HttpKernel example:

```
class HttpKernel implements HttpKernelInterface
{
    public function handle(Request $request): Response
    {
        return Response::make(200, 'OK', [
            'body' => 'Hello World!',
        ]);
    }
}
```

Note: The application will automatically send the response created by the Kernel.

Release Notes for v2.0
----------------------

[](#release-notes-for-v20)

### Breaking/Major Changes

[](#breakingmajor-changes)

- Breaking: The `ResponseInterface::send()` method now returns `static` instead of `void`. This change affects the interface and all implementing classes.
- Major: The Application class now automatically sends the response returned by the Kernel.

### New Features

[](#new-features)

- Headers are now buffered in the Response class instead of being sent immediately.
- New protected `sendHeaders()` method added to the Response class for sending all buffered headers.
- New `HtmlResponse` class added for handling HTML responses with appropriate headers.

### Improvements

[](#improvements)

- The `Response::send()` and `JsonResponse::send()` methods now return `$this`, allowing for method chaining and providing more flexibility when working with responses.
- The application now automatically sends the response returned by the Kernel, removing the need to call `send()` manually. This fixes a common "gotcha" where users forget to call `send()` after creating a response.
- Type hints now use `static` returns instead of `self` to more accurately reflect the return type of the methods.
- More flexibility in manipulating headers throughout the response lifecycle.
- Better alignment with common practices in modern PHP frameworks.

### Upgrade Guide

[](#upgrade-guide)

If you're upgrading from v1.x to v2.0, here are the key changes you need to be aware of:

#### Response::send() Method Return Type

[](#responsesend-method-return-type)

1. The `send()` method in the `ResponseInterface` now has a return type of `static`. This is a breaking change as it requires all implementing classes to update their method signature.
2. If you have any custom classes implementing `ResponseInterface`, you must update their `send()` method to return `static`:

    ```
    public function send(): static
    {
        // Your implementation

        return $this;
    }
    ```

Please review your codebase for any implementations of `ResponseInterface` and update them accordingly. This change is made to allow for method chaining and provide more flexibility when working with responses, and to allow for working with sent responses in a more fluent way.

#### Response Creation and Sending

[](#response-creation-and-sending)

The `Application` class is now responsible for sending the response after the kernel handles the request, meaning you should no longer call `send()` manually after creating a response.

Example of updated usage:

```
// In your HttpKernel or similar class
public function handle(Request $request): Response
{
    return Response::make(200, 'OK', ['body' => 'Hello World!']);
    // OR: return new Response(200, 'OK', ['body' => 'Hello World!']);
}

// In your application entry point
$app = new Application(new MyHttpKernel());
$app->handle(); // This will now send the response
```

Please review your codebase for any cases where you send responses manually, as it's no longer necessary to call `send()` after creating a response. The application will automatically send the response returned by the kernel.

#### Header Sending Changes

[](#header-sending-changes)

1. The `withHeaders()` method now adds headers to a buffer instead of sending them immediately. If you were relying on immediate header sending, you may need to adjust your code.
2. Headers are now sent when the `send()` method is called on the Response object. Make sure you're calling `send()` at the appropriate time in your application lifecycle.
3. If you've extended the Response or JsonResponse classes, you may need to update your implementations to work with the new buffered header approach.
4. Update any tests that were checking for immediate header sending. You may need to use reflection or mock the header functions to test the new buffering behavior.

#### New HtmlResponse Class

[](#new-htmlresponse-class)

A new `HtmlResponse` class has been added to handle HTML responses. This class automatically sets the appropriate Content-Type and Content-Length headers for HTML content. If you're returning HTML responses, consider using this new class:

```
use Desilva\Microserve\HtmlResponse;

// In your HttpKernel or similar class
public function handle(Request $request): Response
{
    return new HtmlResponse(200, 'OK', ['body' => 'Hello World!']);
}
```

#### Conclusion

[](#conclusion)

If you encounter any issues during the upgrade process, please open an issue on the GitHub repository.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~110 days

Recently: every ~0 days

Total

8

Last Release

673d ago

Major Versions

v1.0.5 → v2.0.02024-07-14

### Community

Maintainers

![](https://www.gravatar.com/avatar/71ba01b4aa7fbc633c6fe6630b573400b40928d79574b657eb8d45524ca28aa0?d=identicon)[caendesilva](/maintainers/caendesilva)

---

Top Contributors

[![emmadesilva](https://avatars.githubusercontent.com/u/95144705?v=4)](https://github.com/emmadesilva "emmadesilva (147 commits)")[![caendesilva](https://avatars.githubusercontent.com/u/225740250?v=4)](https://github.com/caendesilva "caendesilva (1 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

desilvamicroserve

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/desilva-microserve/health.svg)

```
[![Health](https://phpackages.com/badges/desilva-microserve/health.svg)](https://phpackages.com/packages/desilva-microserve)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
