my simple php script simply hangs up when i see in firebug
<?php
require 'FirePHPCore/fb.php';
ob_start();
session_start();
FB::log('Log message');
//FB::info('Info message');
//FB::warn('Warn message');
//FB::error('Error message');
FB::info('i m inside');
$fileCount = $_POST['count'];
$data = "i-" . $fileCount;
FB::info('data for server ' . $data);
$address = '127.0.0.1';
$port = 5555;
set_time_limit(0);
$socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
socket_connect($socket, $address, $port);
FB::info('socket connect ');
$len = strlen($data);
$status = socket_sendto($socket, $data, $len, 0, $address, $port);
$input = socket_read($socket, 1024);
echo $input;
socket_close($socket);
FB::log('i m deadout..');
What is the reason behind this problem please help? thanks. The server (java) running on same machine.
I found out this problem when i saw firebug it simply displays loading icon. And when i remove the socket programming part it works properly.
php socket connections are opened in blocking mode by default and you need to set using socket_set_nonblock. For an example;
$this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_set_nonblock($this->soc);
or
$socket = socket_create_listen(1223);
socket_set_nonblock($socket);
socket_accept($socket);