Code Monkey home page Code Monkey logo

Comments (3)

jingjingxyk avatar jingjingxyk commented on August 14, 2024

协程写法:
写法例子: HTTP/WebSocket客户端

use Swoole\Coroutine;
use Swoole\Coroutine\Http\Client;
use function Swoole\Coroutine\run;

run(function () {
    $client = new Client('127.0.0.1', 9501);
    $ret = $client->upgrade('/');   # 最关键点就是这里了。
    if ($ret) {
        while(true) {
            $client->push('hello');
            var_dump($client->recv());
            Coroutine::sleep(0.1);
        }
    }
});

这里有不少使用例子:

https://github.com/swoole/swoole-src/tree/master/examples/coroutine/websocket
https://github.com/swoole/swoole-src/tree/master/tests/swoole_http_client_coro/websocket

from swoole-cli.

jingjingxyk avatar jingjingxyk commented on August 14, 2024

老版本是异步写法 swoole websocket client https://wiki.swoole.com/wiki/page/p-http_client.html

这个我没有用过。

https://wiki.swoole.com/wiki/history/?id=533

例子:
https://github.com/swoole/swoole-src/blob/4.8.x/examples/websocket/client.php
https://github.com/swoole/swoole-src/blob/4.8.x/tests/include/api/swoole_websocket_server/websocket_client.php

examples/websocket/async_client.php

from swoole-cli.

jingjingxyk avatar jingjingxyk commented on August 14, 2024

搜索引擎 搜索信息:
https://www.baidu.com/s?ie=utf-8&wd=WebSocket+%E5%AE%A2%E6%88%B7%E7%AB%AF%20%20site:swoole.com

https://cn.bing.com/search?q=WebSocket+%E5%AE%A2%E6%88%B7%E7%AB%AF%20site:swoole.com

https://www.google.com/search?q=WebSocket+%E5%AE%A2%E6%88%B7%E7%AB%AF%20site:swoole.com

from swoole-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.