aisstream / issues

7 stars 3 forks source link

Php Example #10

Closed Barquero-lab closed 1 year ago

Barquero-lab commented 1 year ago

Is it possible to connect from php? Something Similar to:

<?php
require('../vendor/autoload.php');
$client = new WebSocket\Client("wss://stream.aisstream.io/v0/stream"); 
$client->text( json_encode( array('Apikey' => '------------', 'BoundingBoxes' => [[[35,-11],[44,6]]]) ) );
echo '<pre>';
$i = 0; 
while ( $i < 100) {
    try {
        print_r( $client->receive() );      
        $i++;
        echo '<br>';
      } catch (\WebSocket\ConnectionException $e) {
        print_r("Error: ".$e->getMessage());
    }
}
$client->close();
?>

Edit: It worked :-)