PHP Regex
2024-09-28 06:39:14
<?php //Accpet the http client request and generate response content.
//As a demo, this function just send "PHP HTTP Server" to client.
function handle_http_request($address, $port)
{
$max_backlog = 16;
$res_content = "HTTP/1.1 200 OK
Content-Length: 15
Content-Type: text/plain; charset=UTF-8 PHP HTTP Server";
$res_len = strlen($res_content); //Create, bind and listen to socket
if(($socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === FALSE)
{
echo "Create socket failed!\n";
exit;
} if((socket_bind($socket, $address, $port)) === FALSE)
{
echo "Bind socket failed!\n";
exit;
} if((socket_listen($socket, $max_backlog)) === FALSE)
{
echo "Listen to socket failed!\n";
exit;
} //Loop
while(TRUE)
{
if(($accept_socket = socket_accept($socket)) === FALSE)
{
continue;
}
else
{
socket_write($accept_socket, $res_content, $res_len);
socket_close($accept_socket);
}
}
} //Run as daemon process.
function run()
{
if(($pid1 = pcntl_fork()) === 0)
//First child process
{
posix_setsid(); //Set first child process as the session leader. if(($pid2 = pcntl_fork()) === 0)
//Second child process, which run as daemon.
{
//Replaced with your own domain or address.
handle_http_request('www.codinglabs.org', 9999);
}
else
{
//First child process exit;
exit;
}
}
else
{
//Wait for first child process exit;
pcntl_wait($status);
}
} //Entry point.
run(); ?>
最新文章
- STM32 NVIC配置详解
- 将PDM文件导出成CHM帮助文件
- lipo命令
- phpstorm使用技巧
- 软件版本中的Alpha,Beta,RC,Trial是什么意思?
- spring sts 从数据库中反向生成实体类
- <;一年成为Emacs高手>;更新到20130706版
- Eclipse中集成Perforce插件
- Robot Framework中经常用的第三方库的安装方法
- linux 操作系统/xxx目录下都是什么文件?
- iOS开发所有KeyboardType与图片对应展示
- Windows10文件目录下添加 Shift+右键打开管理员Powershell窗口
- c++ 之模板进阶
- 从PRISM开始学WPF(番外)共享上下文 RegionContext-更新至Prism7.1
- activemq配置安装
- 分组PARTITION BY及游标CURSOR的用法
- three.js中的文字
- JS事件(五)内存与性能
- vue cli3.0 结合echarts3.0和地图的使用方法
- IDC:IDC(互联网数据中心)