Introduction to php network programming

不言
Release: 2023-03-23 07:40:01
Original
2936 people have browsed it

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);
?>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!