https://github.com/akmalfairuz/vnet
TCP Networking Library written in PHP
https://github.com/akmalfairuz/vnet
Last synced: about 2 months ago
JSON representation
TCP Networking Library written in PHP
- Host: GitHub
- URL: https://github.com/akmalfairuz/vnet
- Owner: AkmalFairuz
- License: apache-2.0
- Created: 2021-08-20T06:35:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-08-20T07:22:02.000Z (over 3 years ago)
- Last Synced: 2025-03-29T02:47:38.082Z (about 2 months ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VNet
A TCP Networking library written in PHP with pthreads## Requirements
- PHP8
- [pmmp/pthreads](https://github.com/pmmp/pthreads)
- [pmmp/Snooze](https://github.com/pmmp/Snooze)
- ext-socket## Example
```php
getEventHandler()
->onRecv(function (Session $session, string $packet) : void {
$session->sendPacket(implode("\r\n", [
"HTTP/1.1 200 OK",
"Date: " . gmdate('D, d M Y H:i:s T'),
"Connection: Keep-Alive",
"Server: PHP",
"Content-Type: text/html",
"",
"HelloHello World!
You send:
" . str_replace("\n", "
", $packet)
]));
$session->disconnect(STREAM_SHUT_RDWR);
})
->onConnect(function (Session $session) : void {
// TODO:
})
->onClose(function (Session $session) : void {
// TODO:
});$server->run();
```