Skip to content

Commit

Permalink
Merge pull request #56 from vanodevium/laravel-recipe
Browse files Browse the repository at this point in the history
Some changes for Laravel recipe
  • Loading branch information
joanhey authored Dec 14, 2023
2 parents 8b6190e + 5c270f6 commit 894d4d3
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions recipes/laravel.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
# Laravel with Workerman
# Laravel with Adapterman

Copy your `app/index.php` to `start.php`.
## server.php

## Change the code
In `start.php`
Create `server.php` in the project root directory with next content:
```php
<?php

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

use Adapterman\Adapterman;
use Workerman\Worker;

Adapterman::init();

Change:
$http_worker = new Worker('http://localhost:8080'); // or 127.0.0.1:8080, or localhost:9000
$http_worker->count = cpu_count(); // or any positive integer
$http_worker->name = env('APP_NAME'); // or any string

$http_worker->onWorkerStart = static function () {
require __DIR__.'/start.php';
};

$http_worker->onMessage = static function ($connection, $request) {
$connection->send(run());
};

Worker::runAll();
```

## start.php

Copy your `./public/index.php` to `./start.php`.

### Change the code

In the newly created `start.php`

Replace this part:
```php
/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -33,7 +64,7 @@ $kernel->terminate($request, $response);

```

To:
With this part:
```php
/*
|--------------------------------------------------------------------------
Expand All @@ -47,7 +78,7 @@ To:
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';
$app = require_once __DIR__.'/bootstrap/app.php';

global $kernel;

Expand Down Expand Up @@ -75,8 +106,12 @@ function run()
```

## Run your app
```php server.php start ```

In the project root directory run:

```shell
php server.php start
```

View in your browser

Expand Down

0 comments on commit 894d4d3

Please sign in to comment.