Is it possible (and practicable) to develop a (simple) server software using the PHP CLI SAPI? Is there some usable way of (real) multi-threading in PHP so the server is able to handle several request simultaneously? Or would you recommend another Scripting language for a project like this (Python or something like that)?
2条回答 默认 最新
- dpqg86714 2012-12-14 14:14关注
Yes it is possible to develop a TCP or UDP server in PHP. Have a look at the set of socket functions in PHP: PHP:Sockets - Manual
Although PHP has no multithreading capabilities you can create simple parallelism using non blocking IO (see
socket_set_nonblock()
) along withsocket_select()
To answer the question 'Is it practible' it needs more information about the project requirements. Reasons for a 'yes' could be:
- You need to integrate the server into an existing PHP class, model framework
- You plan to interexchange PHP data structures using the server. (Might be generated using
serialize()
,unserialize()
)
You may find additional reasons for you of course.
Another thing you should note is that when in web server environment (e.g apache SAPI) you already have a parallel TCP server - the web server. You would just have to implement the communication between several requests. You may use PHP's IPC capabilities, a database or at least a file for that communication.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 MATLAB动图问题
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名