PHP code example of scil / laravel-fly
1. Go to this page and download the library: Download scil/laravel-fly library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scil / laravel-fly example snippets
// ensure ` const LARAVELFLY_COROUTINE = true;` in fly.conf.php
Route::get('/fly', function () {
$a = [];
fly(function () use (&$a) {
$a[] = 'coroutine1';
\co::sleep(2);
$a[] = 'coroutine1.end';
\Log::info(implode('; ', $a));
// Eloquent can be used even if current request has ended.
// $user = new User();
// $user->name = implode('; ',$a);
// $user->save();
});
$a[] = 'outer1';
// go() can use laravel service with closure
$log = app('log');
go(function () use (&$a, $log) {
$a[] = 'coroutine2';
\co::sleep(1.2);
$a[] = 'coroutine2.end';
});
$a[] = 'outer2';
\co::sleep(1);
$a[] = 'outer3';
return implode(';', $a);
});