请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Swoole\Server can only be used in CLI mode in

在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不知道是哪里出的问题

正在回答 回答被采纳积分+3

插入代码

1回答

singwa 2019-08-05 16:44:37

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

0 回复 有任何疑惑可以回复我~
  • 提问者 小冰糕 #1
    <?php
    $http = new swoole_http_server("127.0.0.1", 9501);
    
    $http->on("start", function ($server) {
        echo "Swoole http server is started at http://127.0.0.1:9501\n";
    });
    
    $http->on("request", function ($request, $response) {
        $response->header("Content-Type", "text/plain");
        $response->end("Hello World\n");
    });
    
    $http->start();
    
    就是官网上首页中的httpserver的代码,直接复制过去做测试的
    回复 有任何疑惑可以回复我~ 2019-08-05 16:46:23
  • 提问者 小冰糕 #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 16:55:59
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号