DEV Community

Sergey Telpuk
Sergey Telpuk

Posted on

2 1

Roadrunner & Zend Expressive & Cycle ORM. Not allow to php to die.

Hello everyone! This article is dedicated to run PHP-application under Roadrunner(RR). if you haven't gotten acquainted with RR yet, I put forward to visiting the link.
In my past article, I tried to describe how easy to integrate Cycle ORM into ZE, but it isn't so interesting like setting up the following stack: Roadrunner, Zend Expressive, Cycle ORM. Maybe It'll give you another way of starting off your new application with that one.
ZE isn't so popular among PHP developers. From my point of view It's underestimated micro-framework because of that there was chosen ZE. So, go ahead!

I don't like to get a deal with setting local-env, so I give my preference in favor of docker. I prepared the repository for running RR with the help of docker-compose, It can be found by the following link.

After cloned roadrunner-docker-skeleton. We can use Makefile for building and running.
For the first step, run Makefile command:

make build

Note: don't forget copy sample.env into .env.

For the next step, should install ZE skeleton application:

docker-compose run composer create-project zendframework/zend-expressive-skeleton expressive  

For the next step, change file expressive/public/index.php:

<?php declare(strict_types=1);

chdir(dirname(__DIR__));
require 'vendor/autoload.php';

return (function () {
    $container = require 'config/container.php';
    $app = $container->get(\Zend\Expressive\Application::class);
    $factory = $container->get(\Zend\Expressive\MiddlewareFactory::class);
    (require 'config/pipeline.php')($app, $factory, $container);
    (require 'config/routes.php')($app, $factory, $container);

    return $app;
})();

For the next step, change file worker.php:

<?php declare(strict_types=1);

ini_set('display_errors', 'stderr');

chdir(dirname(__DIR__));
require 'vendor/autoload.php';

$app = require 'expressive/public/index.php';

$relay = new Spiral\Goridge\StreamRelay(STDIN, STDOUT);
$psr7 = new Spiral\RoadRunner\PSR7Client(new Spiral\RoadRunner\Worker($relay));

while ($req = $psr7->acceptRequest()) {
    try {
        $response = $app->handle($req);
        $psr7->respond($response);
    } catch (\Throwable $e) {
        $psr7->getWorker()->error((string)$e);
    }
}

For using Cycle ORM under ZE to follow the link.
Finish step is to run our RR:

make up

Enjoy, http://localhost:8080

Quadratic AI

Quadratic AI – The Spreadsheet with AI, Code, and Connections

  • AI-Powered Insights: Ask questions in plain English and get instant visualizations
  • Multi-Language Support: Seamlessly switch between Python, SQL, and JavaScript in one workspace
  • Zero Setup Required: Connect to databases or drag-and-drop files straight from your browser
  • Live Collaboration: Work together in real-time, no matter where your team is located
  • Beyond Formulas: Tackle complex analysis that traditional spreadsheets can't handle

Get started for free.

Watch The Demo πŸ“Šβœ¨

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

πŸ‘‹ Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay