我正在听一个跟踪器设备的套接字,我在公共文件夹中创建了一个php类,在该文件中我访问Redis类将数据发布到服务器,但是我收到以下错误:< / p>
Stack trace:
#0 C:\xampp\htdocs\www\socket5\public\socket-server.php(38): Illuminate\Support\Facades\Facade::__callStatic('publish', Array)
#1 {main}
thrown in C:\xampp\htdocs\www\socket5\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 218
Fatal error: Uncaught RuntimeException: A facade root has not been set. in C:\xampp\htdocs\www\socket5\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php:
218
这是我得到的错误。这就是我在做的事情:
use \Illuminate\Support\Facades\Facade as Facade;
use Illuminate\Support\Facades\Redis;
Redis::publish('test-channel', json_encode($data));
这就是我在听socket的方式:
$server = stream_socket_server("tcp://IP_ADDRESS:4000", $errno, $errorMessage);
if ($server === false) {
throw new UnexpectedValueException("Could not bind to socket: $errorMessage");
}
else {
$i = 0;
for (;;) {
if($i == 0) {
$client = @stream_socket_accept($server);
}
if ($client) {
if($i == 0) {
$message= fread($client, 80000);
echo $message;
$response=pack("H*","01");
fwrite($client, $response);
$i++;
}
else {
$message= fread($client, 80000);
$data = $message;
echo $message;
if(trim($message) == "") {
fclose($client);
$i = 0;
}
else {
$hexData = bin2hex($message);
$decoder = new TeltonikaFmParser\TcpDecoder();
$original_data = $decoder->decodeData($hexData);
echo $json_string = json_encode($original_data);
$data = [
'event' => 'UserSignedUp',
'data' => $original_data
];
Redis::publish('test-channel', json_encode($data));
//insertintodatabase($json_string);
fclose($client);
$i = 0;
}
}
}
}
}
我已经搜索过这个但是找不到任何东西。任何帮助将不胜感激。
如果有人可以帮助如何在laravel中听一个插座也很棒。
答案 0 :(得分:0)
您提供的代码不属于公共目录&amp;它不应该使用网络服务器运行,你应该使用终端来运行它...我想你可以把它变成自己的工匠命令