ID:33090
 
Keywords: php_dm, sockets
This is a function to make PHP communicate with DM, courtesy of Mobius Evalon and Crispy!

function export($addr,$port,$str)
{
if($str{0} != "?") $str = ("?" . $str);
$query = "\x00\x83" . pack("n",strlen($str)+6) . "\x00\x00\x00\x00\x00" . $str . "\x00";
$server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or exit('Unable to create export socket; ' . socket_strerror(socket_last_error()));
socket_connect($server,$addr,$port) or exit('Unable to establish socket connection; ' . socket_strerror(socket_last_error()));
$bytessent = 0;
while($bytessent < strlen($query))
{
$result = socket_write($server,substr($query,$bytessent),strlen($query)-$bytessent);
if($result === FALSE) exit('Unable to transfer requested data; ' . socket_strerror(socket_last_error()));
$bytessent += $result;
}
socket_close($server);
}


And for an example:

export("127.0.0.1",1766,"dothisaction");


This will send 127.0.0.1:1766 a message saying "dothisaction," which it will receive via world/Topic.