Search code examples
phplinuxwampfwrite

fwrite return int(0) on web server but not on Wamp


I am unable to find any issue with this code on my shared hosting. It is returning (int)0, but on my wamp server it is returning the correct bytes. The IP address is taken from gametracker public servers.

Code

$socket = fsockopen( 'udp://51.75.36.115', '25565' );
$packet = pack("c3N", 0xFE, 0xFD, 0x09, 2);
$fwrite = fwrite($socket, $packet, strlen($packet));
var_dump( $fwrite);

Response

int(0)

I have checked all the php configurations and all modules. I am not getting anything in the error logs.


Solution

  • Turns out it was server restrictions, you cannot do this on shared hosting, you need a cloud or dedicated server.