PHP code example of cooper / canal-client

1. Go to this page and download the library: Download cooper/canal-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cooper / canal-client example snippets




use Cooper\CanalClient\CanalClient;
use Cooper\CanalClient\CanalConnectorFactory;
use Cooper\CanalClient\Fmt;

_SOCKET);
    // $client = CanalConnectorFactory::createClient(CanalClient::TYPE_SWOOLE);
    // $client = CanalConnectorFactory::createClient(CanalClient::TYPE_SOCKET_CLUE);

    // Connect to Canal server
    $client->connect("127.0.0.1", 11111);

    // Subscribe to changes (clientId, destination, filter)
    $client->subscribe("1001", "example", ".*\\..*");
    // $client->subscribe("1001", "example", "db_name.tb_name");

    while (true) {
        $message = $client->get(100);
        if ($entries = $message->getEntries()) {
            foreach ($entries as $entry) {
                Fmt::println($entry);
            }
        }
        sleep(1);
    }
} catch (\Exception $e) {
    echo $e->getMessage(), PHP_EOL;
}