Skip to content

Instantly share code, notes, and snippets.

View lotharthesavior's full-sized avatar

Sávio Resende lotharthesavior

View GitHub Profile
<?php
// app/Http/Controllers/TutoringController.php
use App\Models\Student;
use Illuminate\Http\Request;
class TutoringController extends Controller
{
public function updateRecommendations(Student $student)
@lotharthesavior
lotharthesavior / openswoole-redis-pubsub.php
Last active September 16, 2022 03:00
OpenSwoole Redis PubSub Test 1
<?php
Co::set(['hook_flags' => SWOOLE_HOOK_TCP]);
Co\run(function()
{
// refresh
$redis0 = new Redis();
$redis0->connect('127.0.0.1', 6379);
$redis0->flushDB();
@lotharthesavior
lotharthesavior / openmetrics.php
Created June 19, 2022 13:50 — forked from johanjanssens/openmetrics.php
Openswoole - getMetrics()
<?php
/**
* Extracted from https://github.com/openswoole/swoole-src/blob/f191c0b0a98e9b97f5c81d4877f450c863e6c36d/ext-src/php_swoole_library.h#L6999
*
* Changes:
*
* - Added 'service' label
* - Added additional label support
*
@lotharthesavior
lotharthesavior / script.php
Last active June 4, 2022 00:55
Finding the first available time for 2 users
<?php
/**
Give the data is this:
[
{
"name":"Joe",
"meetings":[
@lotharthesavior
lotharthesavior / client.php
Last active May 25, 2022 04:32
PHP OpenSwoole Atomic forcing one worker to wait for another
<?php
Co\run(function() {
go(function() {
echo "==========================================" . PHP_EOL;
echo file_get_contents('http://localhost:8282/requestA') . PHP_EOL;
echo "==========================================" . PHP_EOL;
});
@lotharthesavior
lotharthesavior / client.php
Created May 20, 2022 02:22
OpenSwoole Timer syncing multiple workers data
<?php
Co\run(function() {
go(function () {
var_dump(file_get_contents('http://localhost:9502/requestA'));
});
go(function () {
var_dump(file_get_contents('http://localhost:9502/requestB'));
@lotharthesavior
lotharthesavior / client.html
Last active May 21, 2022 01:25
OpenSwoole WebSocket with WaitGroup example
<script>
let ws = new WebSocket('ws://127.0.0.1:9502');
ws.send("test 1");
setTimeout(() => ws.send("test 2"), 2000);
</script>
@lotharthesavior
lotharthesavior / service.php
Created May 17, 2022 17:41
OpenSwoole Yield/Resume Example
#!/usr/bin/env php
<?php
declare(strict_types=1);
class DataObject
{
public $total = 0;
public $data = [];
public function push($item)
@lotharthesavior
lotharthesavior / Dockerfile
Last active May 16, 2022 04:37
OpenSwoole Docker Dev Environment
FROM ubuntu:20.04
ARG WWWGROUP
ARG SUPERVISOR_CONF
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
@lotharthesavior
lotharthesavior / server.php
Last active May 16, 2022 04:22
Identifying WebSocket Message author with OpenSwoole
<?php
use Swoole\Websocket\Server;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
$server = new Server("0.0.0.0", 9501);
$server->table = (require __DIR__ . DIRECTORY_SEPARATOR . 'user-table.php')();
$server->on("start", function (Server $server) {