Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes for Laravel recipe #56

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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