mirror of
https://github.com/YGGverse/nex-php.git
synced 2026-03-31 17:55:31 +00:00
Compare commits
11 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1129cd1657 | ||
|
|
55b4c879e4 | ||
|
|
7923fea04e | ||
|
|
1aa260b41d | ||
|
|
406911794d | ||
|
|
f80b114f1a | ||
|
|
6795d37fa8 | ||
|
|
3f2b2cbc54 | ||
|
|
52b43a252d | ||
|
|
9daef40268 | ||
|
|
9edd764fa7 |
4 changed files with 38 additions and 10 deletions
15
README.md
15
README.md
|
|
@ -1,6 +1,6 @@
|
||||||
# nex-php
|
# nex-php
|
||||||
|
|
||||||
PHP 8 Library for Nex Protocol
|
PHP 8 Library for NEX Protocol (see also [nps-php](https://github.com/YGGverse/nps-php))
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ composer require yggverse/nex
|
||||||
|
|
||||||
## Client
|
## Client
|
||||||
|
|
||||||
PHP interface for Nex protocol queries
|
PHP interface for NEX protocol queries
|
||||||
|
|
||||||
``` php
|
``` php
|
||||||
$client = new \Yggverse\Nex\Client;
|
$client = new \Yggverse\Nex\Client;
|
||||||
|
|
@ -41,7 +41,7 @@ var_dump(
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
Build interactive server instance to listen Nex protocol connections!
|
Build interactive server instance to listen NEX protocol connections!
|
||||||
|
|
||||||
``` php
|
``` php
|
||||||
$server = new \Yggverse\Nex\Server;
|
$server = new \Yggverse\Nex\Server;
|
||||||
|
|
@ -73,12 +73,15 @@ $server->start(
|
||||||
function (
|
function (
|
||||||
string $request,
|
string $request,
|
||||||
string $connect
|
string $connect
|
||||||
) {
|
): ?string
|
||||||
|
{
|
||||||
printf(
|
printf(
|
||||||
'connection: %s request: %s',
|
'connection: %s request: %s',
|
||||||
$connect,
|
$connect,
|
||||||
$request
|
$request
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return null; // null|string response
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
@ -88,3 +91,7 @@ $server->start(
|
||||||
Stop server instance.
|
Stop server instance.
|
||||||
|
|
||||||
Same to `Server::setLive(false)`
|
Same to `Server::setLive(false)`
|
||||||
|
|
||||||
|
## Integrations
|
||||||
|
|
||||||
|
* [next](https://github.com/YGGverse/next) - PHP 8 Server for NEX Protocol
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "yggverse/nex",
|
"name": "yggverse/nex",
|
||||||
"description": "PHP 8 Library for Nex Protocol",
|
"description": "PHP 8 Library for Nex Protocol",
|
||||||
"keywords": [ "yggverse", "nex", "nex-protocol", "client" ],
|
"keywords": [ "yggverse", "nex", "nex-protocol", "client", "server" ],
|
||||||
"homepage": "https://github.com/yggverse/nex-php",
|
"homepage": "https://github.com/yggverse/nex-php",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,10 @@ class Client
|
||||||
sprintf(
|
sprintf(
|
||||||
"%s%s\r\n",
|
"%s%s\r\n",
|
||||||
$this->_path,
|
$this->_path,
|
||||||
$this->_query
|
$this->_query ? sprintf(
|
||||||
|
'?%s',
|
||||||
|
$this->_query
|
||||||
|
) : null
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,17 @@ class Server
|
||||||
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN
|
STREAM_SERVER_BIND | STREAM_SERVER_LISTEN
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($this->_live)
|
||||||
|
{
|
||||||
|
$this->_live = is_resource(
|
||||||
|
$socket
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (!$this->_live)
|
if (!$this->_live)
|
||||||
{
|
{
|
||||||
fclose(
|
|
||||||
$socket
|
|
||||||
);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -145,6 +148,14 @@ class Server
|
||||||
$request,
|
$request,
|
||||||
$connect
|
$connect
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($response)
|
||||||
|
{
|
||||||
|
fwrite(
|
||||||
|
$incoming,
|
||||||
|
$response
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(
|
fclose(
|
||||||
|
|
@ -152,6 +163,13 @@ class Server
|
||||||
);
|
);
|
||||||
|
|
||||||
} while ($this->_live);
|
} while ($this->_live);
|
||||||
|
|
||||||
|
if (is_resource($socket))
|
||||||
|
{
|
||||||
|
fclose(
|
||||||
|
$socket
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stop(): void
|
public function stop(): void
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue