Skip to content

Instantly share code, notes, and snippets.

@javier
Last active July 19, 2022 10:37
Show Gist options
  • Save javier/9abd482ac3abd9aa714c0359f571bc3e to your computer and use it in GitHub Desktop.
Save javier/9abd482ac3abd9aa714c0359f571bc3e to your computer and use it in GitHub Desktop.
QuestDB ILP PHP
$milliseconds = bcmul(microtime(true), 1000000000) ;
echo strval($milliseconds);
#!//opt/homebrew/bin/php -q
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$address = 'localhost';
$port = 9009;
/* Create a TCP/IP socket. */
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$address' on port '$port'...";
$result = socket_connect($socket, $address, $port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}
$row=utf8_encode("test_readings,city=London,make=Omron temperature=23.5,humidity=0.343 1465839830100400000\n");
echo "$row";
socket_write($socket, $row);
echo "\n";
socket_close($socket);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment