Table of Contents
回复内容:
Home Backend Development PHP Tutorial MAC下安装swoole,在MAMP这块遇到问题

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

Jun 06, 2016 pm 08:30 PM
mac php swoole

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

<code><?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();


</code>
Copy after login
Copy after login

返回:

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


更新于(2015-08-07)
另一方方面:
php -i|grep swoole
返回

<code>swoole
swoole support => enabled
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.message_queue_key => 0 => 0
swoole.unixsock_buffer_size => 8388608 => 8388608
</code>
Copy after login
Copy after login

php -i|more里的

<code>Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.5.18/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.5.18/conf/php.ini,
</code>
Copy after login
Copy after login

phpinfo里的

<code>Configuration File (php.ini) Path=>/Applications/MAMP/bin/php/php5.5.18/conf
Loaded Configuration File=>/Library/Application Support/appsolute/MAMP PRO/conf/php.ini
</code>
Copy after login
Copy after login

发现只有Loaded Congiguration File不同,
首先
1./Applications/MAMP/bin/php/php5.5.18/conf/php.ini已经写了extension=swoole.so
2/Library/Application Support/appsolute/MAMP PRO/conf/php.ini里面没有swoole.so
3.重启MAMP已经尝试过了

回复内容:

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

<code><?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();


</code>
Copy after login
Copy after login

返回:

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


更新于(2015-08-07)
另一方方面:
php -i|grep swoole
返回

<code>swoole
swoole support => enabled
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.message_queue_key => 0 => 0
swoole.unixsock_buffer_size => 8388608 => 8388608
</code>
Copy after login
Copy after login

php -i|more里的

<code>Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.5.18/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.5.18/conf/php.ini,
</code>
Copy after login
Copy after login

phpinfo里的

<code>Configuration File (php.ini) Path=>/Applications/MAMP/bin/php/php5.5.18/conf
Loaded Configuration File=>/Library/Application Support/appsolute/MAMP PRO/conf/php.ini
</code>
Copy after login
Copy after login

发现只有Loaded Congiguration File不同,
首先
1./Applications/MAMP/bin/php/php5.5.18/conf/php.ini已经写了extension=swoole.so
2/Library/Application Support/appsolute/MAMP PRO/conf/php.ini里面没有swoole.so
3.重启MAMP已经尝试过了

phpinfo() 沒 swoole ,說明你可能沒重啟apache. 因為php -m 是實時的.所以看不出來.
建議你 php -i|grep swoole 看下先,如果有.很可能就是apache沒重啟造成的.

mac下還有一種可能性,mac自帶了php. 你swoole安裝到自帶的php上了...
分別看下 php -i|more 里面php的路徑和
phpinfo()路徑,對比下.看是否一致.

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

MAMP的php.ini文件用的是模板,直接在对应版本下的php目录中修改是不会生效的,需要修改模板文件,在MAMP的菜单里面有此项功能,添加扩展之后重启web服务就行

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles