Hi i have a client connecting to a socket server in php.
I want to empty a particular file after connecting to the server, however, the codes is not giving me any error but it is not writing to the file?
<?php
set_time_limit(0);
//parameters to connect to server
$ip = "127.0.0.1";
$port = "1245";
$data = "";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
$result = socket_connect($socket, $ip, $port);
$myFile = "test.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "");
while (true)
{
$data = "some value here"
socket_write($socket, $data, strlen($data));
$line =@socket_read($socket,2048, PHP_NORMAL_READ);
if($line != "")
{
echo $line."
";
}
}
socket_close($socket);
?>