The return appears to be the size in bytes of the data written to the socket, or -1 on failure (this could be because of non blocking)(PHP 5, PHP 7, PHP 8)
stream_socket_sendto — 接続されているかどうかにかかわらず、ソケットにデータを送信する
$socket,$data,$flags = 0,$address = ""
data で指定したデータを
socket で指定したソケットに送信します。
socket
data を送信するソケット。
data送りたいデータ。
flags
flags は以下の値の組み合わせです。
STREAM_OOB |
OOB (out-of-band) データを処理します。 |
address
address で別のアドレスが指定されていない限り、
ソケットストリームが作成された際のアドレスを使用します。
指定する場合は、ドットで 4 つに区切った形式 (あるいは IPv6 形式) でなければなりません。
結果コードを整数値で返します。
失敗した場合に false を返します
例1 stream_socket_sendto() の例
<?php
/* localhost のポート 1234 へのソケットをオープンします */
$socket = stream_socket_client('tcp://127.0.0.1:1234');
/* 普通のデータを普通のチャネルで送信します */
fwrite($socket, "Normal data transmit.");
/* 帯域外のデータを送信します */
stream_socket_sendto($socket, "Out of Band data.", STREAM_OOB);
/* ソケットを閉じます */
fclose($socket);
?>The return appears to be the size in bytes of the data written to the socket, or -1 on failure (this could be because of non blocking)