MAC下安装swoole,在MAMP这块遇到问题


在MAC下安装swoole,顺着文档安装也成功了,具体的细节是:
我把系统的php切换成MAMP的php,然后安装swoole。最后的php -m命令中也已经有swoole在了,但是phpinfo中却搜索不到swoole的字样
然后使用如下代码测试


 <?php

class Client
{
    private $client;

    public function __construct() {
        $this->client = new swoole_client(SWOOLE_SOCK_TCP);
    }

    public function connect() {
        if( !$this->client->connect("127.0.0.1", 9501 , 1) ) {
            echo "Error: {$fp->errMsg}[{$fp->errCode}]\n";
        }
        $message = $this->client->recv();
        echo "Get Message From Server:{$message}\n";

        fwrite(STDOUT, "请输入消息:");
        $msg = trim(fgets(STDIN));
        $this->client->send( $msg );
    }

    public function test() {
        $this->client = new swoole_client(SWOOLE_SOCK_TCP);

    }
}

$client = new Client();
$client->connect();

返回:

Fatal error: Class 'swoole_client' not found in /Applications/MAMP/htdocs/swoole_example/01/swoole_simple_client.php on line 8

swoole mamp mac php

暮瞳D迪昇※ 8 years, 12 months ago

这个问题原因是你编译swoole生成swoole.so文件的php版本和你现在使用加载swoole的php版本不一致才导致报错的!
你可以用你当前使用的php重新编译一下swoole,生成swoole.so文件,然后在加载。
配置的时候记得指定 --php-config=你当前使用php的php-config路径!

yamoe answered 8 years, 12 months ago

Your Answer