Swoole\Server can only be used in CLI mode in

来源:4-4 Swoole - HTTP服务(上)

小冰糕

2019-08-05

在7.2php环境(lnmp安装的)+4.4.3swoole版本,运行<?php
$http = new swoole_http_server(“127.0.0.1”, 9501);

http−>on("start",function(http->on("start", function (http>on("start",function(server) {
echo “Swoole http server is started at http://127.0.0.1:9501\n”;
});

http−>on("request",function(http->on("request", function (http>on("request",function(request, $response) {
$response->header(“Content-Type”, “text/plain”);
$response->end(“Hello World\n”);
});

$http->start();

在linux服务器上php运行该文件后确实出现Swoole http server is started at http://127.0.0.1:9501但是因为这个服务器是阿里云服务器,已经配好了域名(配好了https),通过我本地windows电脑访问该域名下的该文件(域名/ceshi.php)后提示Fatal error: Uncaught Swoole\Exception: Swoole\Http\Server can only be used in CLI mode in /www/jianghaodong.top/ceshi.php:2 Stack trace: #0 /www/jianghaodong.top/ceshi.php(2): Swoole\Server->__construct(‘127.0.0.1’, 9501) #1 {main} thrown in /www/jianghaodong.top/ceshi.php on line 2不知道是哪里出的问题

写回答

1回答

singwa

2019-08-05

您好。您ceshi.php 文件是干嘛用的,代码贴出来我看看。

0
2
小冰糕
目前的情况是在服务器上运行该代码是正常的,用php命令执行后echo "Swoole http server is started at http://127.0.0.1:9501\n"这句代码确实起了效果打印出来,但是在linux上保持该端口的监听后从本地windows的电脑通过浏览器访问该域名下的该文件就会报这个错误Uncaught Swoole\Exception: Swoole\Http\Server can only be used in CLI mode in /www/jianghaodong.top/ceshi.php:2
2019-08-05
共2条回复

Swoole入门到实战打造高性能赛事直播平台

swoole创始人推荐,借助Swoole打造高性能直播平台

2228 学习 · 1062 问题

查看课程