I'm writing a simple socket code to write data to using socket_write() and in return retrieve data using socket_read().
This is basic set-up that I have:
$socket = socket_create(AF_INET, SOCK_STREAM, 0) or die ("Could not create connection");
$socket_conn = socket_connect($socket, "some_ip", some_digit); // internal network
$socket_params = pack('I',0) . strval($file['filename'] .'.'. $file['extension']) . pack('I', $file['size']) . pack('I', 0) . strval(File::read($file['saved_to'] . $file['saved_as'], true)) . pack('I', 0);
$t = socket_write($socket, $socket_params, strlen($socket_params)) or die ("Could not create connection");
$status = unpack('I', socket_read($socket, 4));
socket_close($socket);
After running this, I will get the error ErrorException [ Warning ]: unpack() [function.unpack]: Type I: not enough input, need 4, have 0
. I'm not sure why this is happening as $t
returns 7423 which is the size I get if I var_dump($socket_params)
.
However at the server side, it's showing that it has only received 1448 bytes and the request therefore got terminated. The server-side is working fine with the current live PHP implementation so I'm ruling out any funkiness with the server-side for now.
I've uploaded my test-code to production to test (on the exact same server as the current live one) and it's returning the same error.
For what's worth, I'm using FuelPHP 1.0 RC3, and the current live implementation is using CakePHP. Local machine is a OS X 10.6.8(MAMP 1.9.4) and production machine is a 10.04 LTS(Apache/PHP5.3.x).
Lastly, I've been searching and since it's having the same issue on Linux machine, I think it's safe to rule this out too (http://stackoverflow.com/questions/6878603/strange-raw-socket-on-mac-os-x http://sock-raw.org/papers/sock_raw) right? I'm not quite sure how to work around this, if it's the problem?
Thanks in advance, I'm not sure what other information I need to provide as this is my first time doing socket programming. I could use some guidance for debugging so fire away any advice!