Ben benim diğer uygulama ile gelecekteki kullanım için PHP Windows için bir inetd gibi hizmet oluşturmak çalışıyorum.
Yani aklınıza gelebilecek tüm Buhar Server kullanmak ve (inetd gibi) süreci doğrudan boruya akışı proc_open etmektir. Windows üzerinde hiçbir pcntl_fork (), ve PHP diş desteklemediği için.
Şimdiye kadar, burada benim kodudur. inetdtest program tek printf (C yazılı) ile basit bir programdır. Ama sorun (netcat ile) benim sunucuya bağlandığında, ben hiçbir yanıt mesaj var olmasıdır.
<?php
define ('SERVICE_COMMAND', 'inetdtest');
define ('SERVICE_PORT', 35123);
function main() {
echo "Simple inetd starting...\n";
$socket = stream_socket_server('tcp://0.0.0.0:' . SERVICE_PORT, $errno, $errstr, STREAM_SERVER_BIND|STREAM_SERVER_LISTEN);
if ($socket === false) {
echo "Can't bind to service port.\n";
echo "[$errno] $errstr";
die(1);
}
$processes = array();
while (true) {
$current = @stream_socket_accept($socket, 5, $host);
if ($current !== false) {
echo 'Incomming connection from client ' . $host . "\n";
echo "Lunching child process... ";
$io = array(
0 => $current,
1 => $current,
2 => array('file', 'stderr.log', 'a')
);
$proc = proc_open(SERVICE_COMMAND, $io, $pipes, NULL, NULL, array('bypass_shell'));
$status = proc_get_status($proc);
echo " DONE! PID : {$status['pid']}\n";
$processes[] = array($current, $proc);
}
foreach ($processes as $k=>$v) {
$status = proc_get_status($v[1]);
if (false === $status['running']) {
echo "Finalizing process {$status['pid']}... ";
fflush($v[0]);
fclose($v[0]);
proc_close($v[1]);
unset($processes[$k]);
echo "DONE!\n";
}
}
}
}
main();