Home >Backend Development >PHP Tutorial >Introduction to php network programming
This article introduces you to the code of PHP network programming. Friends who are interested can take a look at
<?php //echo gethostbyname("www.baidu.com"); $host = "111.13.100.92"; //设置基本信息 $port = 65530; set_time_limit(0); //设置超时时间 //创建一个socket $socket = socket_create(AF_INET,SOCK_STREAM,0) or die("不能建立socket链接!\n"); //绑定Socket到端口 $result = socket_bind($socket,$host,$port) or die("不能绑定socket给定的端口\n"); //开始监听 $result = socket_listen($socket,3) or die("建立socket连接失败\n"); //接受连接请求,另一个Socket处理通讯 $socket_a = socket_accept($socket) or die("不能接受客户端socket请求\n"); //获取客户端的输入请求 $input = socket_read($socket_a,4096) or die("读取客户端输入失败\n"); //清空输入字符 $input = trim($input); //处理客户端输入并处理结果 $output = strrev($input)."\n"; socket_write($socket_a,$output,strlen($output)) or die("不能给客户端返回结果\n"); //关闭socket socket_close($socket_a); socket_close($socket); ?>
Related recommendations:
Page value transfer for getting started with php Analysis of skills
The above is the detailed content of Introduction to php network programming. For more information, please follow other related articles on the PHP Chinese website!