An open API service indexing awesome lists of open source software.

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

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",
"",
"Hello

Hello 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();
```