Skip to content

Instantly share code, notes, and snippets.

View Ste1io's full-sized avatar

Stelio Kontos Ste1io

View GitHub Profile
@miguelmota
miguelmota / tcp_server.php
Created September 4, 2018 01:02
PHP TCP server example
<?php
$host = "127.0.0.1";
$port = 3000;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
$result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
$result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
while(true) {
$spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
@miguelmota
miguelmota / util.php
Last active July 31, 2024 09:14
PHP byte array to hex, hex to byte array, string to hex, hex to string utility functions
<?php
function string2ByteArray($string) {
return unpack('C*', $string);
}
function byteArray2String($byteArray) {
$chars = array_map("chr", $byteArray);
return join($chars);
}