Closed veleton777 closed 4 years ago
@veleton777 Seems, that smt with your payload. Looks like the issue from PHP, @wolfy-j could you please take a look?
Most likely something echoed to the STDOUT, check your Loggers or switch to Unix sockets.
2020-09-28 19:18:49 [52.0.253.201][-][-][error][Spiral\Goridge\Exceptions\PrefixException] Spiral\Goridge\Exceptions\PrefixException: unable to read prefix from socket: Undefined error: 0 in /Users/veleton777/sites/php/services-site/yii-bot/vendor/spiral/goridge/src/SocketRelay.php:305
rr config
env:
YII_DEBUG: true
YII_ENV: dev
YII_ALIAS_WEBROOT: ./web/
YII_ALIAS_WEB: 'http://127.0.0.1:8080/'
http:
address: 0.0.0.0:8080
workers:
command: "php roadrunner.php"
# connection method (pipes, tcp://:9000, unix://socket.unix). default "pipes"
relay: "unix://socket.unix"
roadrunner.php
$worker = new \Spiral\RoadRunner\Worker(
new \Spiral\Goridge\SocketRelay("socket.unix", null, \Spiral\Goridge\SocketRelay::SOCK_UNIX)
);
roadrunner.php
<?php
ini_set('display_errors', 'stderr');
ini_set('use_cookies', 'false');
ini_set('use_only_cookies', 'true');
defined('YII_DEBUG') or define('YII_DEBUG', \getenv('YII_DEBUG'));
defined('YII_ENV') or define('YII_ENV', \getenv('YII_ENV'));
// Load your vendor dependencies and Yii2 autoloader
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
$worker = new \Spiral\RoadRunner\Worker(
new \Spiral\Goridge\SocketRelay("socket.unix", null, \Spiral\Goridge\SocketRelay::SOCK_UNIX)
);
$psr7 = new \Spiral\RoadRunner\PSR7Client($worker);
// Load your configuration file
$config = require_once __DIR__ . '/config/web.php';
$application = (new \yii\Psr7\web\Application($config));
// Handle each request in a loop
while ($request = $psr7->acceptRequest()) {
try {
$response = $application->handle($request);
$psr7->respond($response);
} catch (\Throwable $e) {
// \yii\Psr7\web\ErrorHandler should handle any exceptions
// however you should implement your custom error handler should anything slip past.
$psr7->getWorker()->error((string)$e);
}
// Workers will steadily grow in memory with each request until PHP memory_limit is reached, resulting in a worker crash.
// With RoadRunner, you can tell the worker to shutdown if it approaches 10% of the maximum memory limit, allowing you to achieve better uptime.
if ($application->clean()) {
$psr7->getWorker()->stop();
return;
}
}
now an error of a different type
@veleton777 I can guess, that there is no data in the socket $prefixBody === null || $prefixLength !== 17
, but, we definetely should make error messages more user friendly.
@veleton777 Could you please check the data availability in the socket?
Как мне можно проверить наличие данных в сокете?
Через сервер workerman сокеты работают
Как мне можно проверить наличие данных в сокете?
Не мог бы ты писать на английском, пожалуйста, так как данная проблема может возникнуть у тех, кто не говорит по русски.
OS: mac os catalina php 7.4 laravel 7 roadrunner 1.83 using the library https://github.com/Hunternnm/laravel-roadrunner
psr-worker.php
<?php
use Hunternnm\LaravelRoadrunner\RoadrunnerLaravelBridge;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Spiral\Goridge;
use Spiral\RoadRunner;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\StreamFactory;
use Laminas\Diactoros\UploadedFileFactory;
ini_set('display_errors', 'stderr');
require 'vendor/autoload.php';
$worker = new RoadRunner\Worker(
new Goridge\SocketRelay("rr.sock", null, Goridge\SocketRelay::SOCK_UNIX)
);
$psr7 = new RoadRunner\PSR7Client($worker);
$httpFoundationFactory = new HttpFoundationFactory();
/** @var Application $app */
$app = require __DIR__ . '/bootstrap/app.php';
$rr = new RoadrunnerLaravelBridge($app, __DIR__);
$psr7factory = new PsrHttpFactory(
new ServerRequestFactory(),
new StreamFactory(),
new UploadedFileFactory(),
new ResponseFactory()
);
while ($req = $psr7->acceptRequest()) {
try {
$symfonyRequest = $httpFoundationFactory->createRequest($req);
$request = Request::createFromBase($symfonyRequest);
$response = $rr->request($request);
$psr7response = $psr7factory->createResponse($response);
$psr7->respond($psr7response);
} catch (Throwable $e) {
$psr7->getWorker()->error((string)$e);
}
}
.rr.yaml
http:
address: 0.0.0.0:8080
workers:
command: "php psr-worker.php"
relay: "unix://rr.sock"
pool:
numWorkers: 4
destroyTimeout: 3
maxJobs: 0
rpc:
enable: true
listen: tcp://:6001
[2020-10-01 19:57:16] local.ERROR: unable to read prefix from socket: Undefined error: 0 {"exception":"[object] (Spiral\\Goridge\\Exceptions\\PrefixException(code: 0): unable to read prefix from socket: Undefined error: 0 at /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/goridge/src/SocketRelay.php:305)
[stacktrace]
#0 /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/goridge/src/SocketRelay.php(184): Spiral\\Goridge\\SocketRelay->fetchPrefix()
#1 /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/roadrunner/src/Worker.php(54): Spiral\\Goridge\\SocketRelay->receiveSync(NULL)
#2 /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/roadrunner/src/Worker.php(59): Spiral\\RoadRunner\\Worker->receive(Array)
#3 /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/roadrunner/src/HttpClient.php(39): Spiral\\RoadRunner\\Worker->receive(Array)
#4 /Users/veleton777/sites/php/swoole/laravel-swoole/vendor/spiral/roadrunner/src/PSR7Client.php(74): Spiral\\RoadRunner\\HttpClient->acceptRequest()
#5 /Users/veleton777/sites/php/swoole/laravel-swoole/psr-worker.php(43): Spiral\\RoadRunner\\PSR7Client->acceptRequest()
#6 {main}
"}
this error appears when running roadrunner
./rr serve
on ubuntu the same error
Ok, thanks a lot. @Hunternnm, could you please take a look?
I solved the error, the Viber library code contained the file_get_contents ('php://input');
I replaced it with fetching via laravel requests
`[2020-09-27 16:22:13] local.ERROR: unpack(): Type C: not enough input, need 1, have 0 {"exception":"[object] (ErrorException(code: 0): unpack(): Type C: not enough input, need 1, have 0 at /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/goridge/src/StreamRelay.php:152) [stacktrace]
0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'unpack(): Type ...', '/Users/veleton7...', 152, Array)
1 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/goridge/src/StreamRelay.php(152): unpack('Cflags/Psize/Jr...', '')
2 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/goridge/src/StreamRelay.php(118): Spiral\Goridge\StreamRelay->fetchPrefix()
3 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner/src/Worker.php(54): Spiral\Goridge\StreamRelay->receiveSync(NULL)
4 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner/src/Worker.php(59): Spiral\RoadRunner\Worker->receive(Array)
5 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner/src/HttpClient.php(39): Spiral\RoadRunner\Worker->receive(Array)
6 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner/src/PSR7Client.php(74): Spiral\RoadRunner\HttpClient->acceptRequest()
7 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner-laravel/src/Worker.php(61): Spiral\RoadRunner\PSR7Client->acceptRequest()
8 /Users/veleton777/sites/php/roadrunner/laravel-roadrunner/vendor/spiral/roadrunner-laravel/bin/rr-worker(77): Spiral\RoadRunnerLaravel\Worker->start(false)
9 {main}
"}`
get requests work, but post requests from telegrams do not What could be the reason for this error?