PHP code example of huang-yi / laravel-swoole-http
1. Go to this page and download the library: Download huang-yi/laravel-swoole-http 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/ */
huang-yi / laravel-swoole-http example snippets
// Framework: Laravel
// File: config/app.php
[
'providers' => [
HuangYi\Swoole\SwooleServiceProvider::class,
],
];
// Framework: Lumen
// File: bootstrap/app.php
$app->register(HuangYi\Swoole\SwooleServiceProvider::class);
[
'tables' => [
[
'name' => 'users',
'size' => 1024,
'columns' => [
['id', 'int', 8],
['nickname', 'string', 255],
['score', 'float']
],
],
],
];
use HuangYi\Swoole\Facades\Table;
// Insert a record.
Table::use('users')->set(1, ['id' => 1, 'nickname' => 'Bob', 'score' => 9.5]);
// Query a record.
$bob = Table::use('users')->get(1);
$nickname = Table::use('users')->get(1, 'nickname');
// Truncate a table.
Table::truncate('users');
use HuangYi\Swoole\Contracts\TaskContract;
use Illuminate\Support\Facades\Mail;
class SendMailTask implements TaskContract
{
/**
* @var array $mail
*/
protected $mail;
/**
* Mail task
*
* @var array $mail
* @return void
*/
public function __construct(array $mail)
{
$this->mail = $mail;
}
/**
* Task handler.
*
* @param \Swoole\Server $server
* @param int $taskId
* @param int $srcWorkerId
* @return void
*/
public function handle($server, $taskId, $srcWorkerId)
{
Mail::to($this->mail['to'])->send($this->mail['view'], $this->mail['data']);
}
}
$task = new SendMailTask([
'to' => '[email protected] ',
'view' => 'mail',
'data' => [],
]);
app('swoole.server')->task($task);
$ php artisan vendor:publish --provider="HuangYi\Swoole\SwooleServiceProvider"
sh
php artisan swoole:server
sh
php artisan swoole:server
nginx
server {
listen 80;
server_name your.domain;
root /path/to/laravel/public;
index index.php;
location = /index.php {
# Ensure that there is no such file named "not_exists" in your "public" directory.
try_files /not_exists @swoole;
}
location / {
try_files $uri $uri/ @swoole;
}
location @swoole {
set $suffix "";
if ($uri = /index.php) {
set $suffix "/";
}
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:1215$suffix;
}
}