0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

fsockopenにリトライを追加

Last updated at Posted at 2017-11-11

http://192.168.0.5:8000 に接続ができない場合、
以下だと1回で諦める。

1回で諦める
<?php
$fp = fsockopen("192.168.0.5", 8000, $errno, $errstr, 30);

通信状況が悪い場合、何度か再試行してもらいたいのでリトライを入れる。

10回リトライ(1秒間隔)
<?php
for($i=0; $i<10;$i++) {
    $fp = fsockopen("192.168.0.5", 8000, $errno, $errstr, 30);
    if($fp) break;
    sleep(1);
}

PHP: fsockopen - Manual

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?