douhao6557 2013-06-12 22:13
浏览 85

在PHP中设置套接字超时

I'm writing a script in PHP that uses PEAR's Net_Socket. I want to query servers to see if they have any current information. I send in a command and then use $socket->readLine() to get the response. However, if there is not a response, my script just waits forever. Is there anyway to either tell the socket to close after a specific amount of time or to wrap the whole function in a timeout, that if it hasn't returned by the timeout, it halts its execution?

  • 写回答

1条回答 默认 最新

  • douxian4888 2013-06-12 23:07
    关注

    On the same page you linked is a link to setTimeout(): https://pear.php.net/manual/en/package.networking.net-socket.settimeout.php

    Trying calling $socket->setTimeout( $seconds, $milliseconds ); just before calling readLine()

    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误