简体   繁体   中英

Guzzle 6 live data streaming: How to?

Project is consuming URL API which is updating the data every seconds. By using Guzzle 6, How can i refresh the data in browser without AJAX?

    ...
    ...

    $un = 'admin';
    $pa = 'password';
    $base_uri = 'http://example.com:82';
    $uri1 = 'api/instant/connectopc';
    $uri2 = 'api/instant/displaydata?site=SITE';

    $cookieFile = 'jar.txt';
    $cookieJar = new FileCookieJar($cookieFile, true);
    $client = new Client([

        'base_uri' => $base_uri,
        'auth'=>[$un, $pa],
        'cookie'=>$cookieJar,
        'curl' => [
            CURLOPT_COOKIEJAR => 'jar.txt',
            CURLOPT_COOKIEFILE => 'jar.txt'
        ],

    ]);

   $connect = $client->get($uri1);  

   //live data to be refresh every seconds. How to do?

   $live= $client->get($uri2, ['cookies' => $cookieJar]); 
   ...

How to accomplish live data streaming?

You cannot do any live streaming from the same page once browser has closed the connection. You have to open another connection. Via Ajax or another technology like WebSockets for example if you need realtime data exchange.

您无法使用PHP进行实时流式传输。.您需要使用像NodeJS这样的编程语言:) .. PHP在最后结束连接:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM