array( 'method' => 'POST', 'content' => $data ) ); $parameters['http']['header'] = $headers; // Change default timeout ini_set('default_socket_timeout', 30); // Create the connection $stream = @stream_context_create($parameters); $connection = @fopen($HOST_BOSH, 'rb', false, $stream); // Failed to connect! if($connection == false) { header('Status: 502 Proxy Error', true, 502); exit('HTTP/1.1 502 Proxy Error'); } // Allow stream blocking to handle incoming BOSH data @stream_set_blocking($connection, true); // Get the output content $output = @stream_get_contents($connection); } // Cache headers header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // POST output if($method == 'POST') { // XML header header('Content-Type: text/xml; charset=utf-8'); if(!$output) echo(''); else echo($output); } // GET output if($method == 'GET') { // JSON header header('Content-type: application/json'); // Encode output to JSON $json_output = json_encode($output); if(($output == false) || ($output == '') || ($json_output == 'null')) echo($callback.'({"reply":""});'); else echo($callback.'({"reply":'.$json_output.'});'); } // Close the connection if($use_curl) curl_close($connection); else @fclose($connection); ?>