/** * The service method runs the gateway application. It turns the gateway 'on'. You * have to call the service method as the last line of the gateway script after all of the * gateway configuration properties have been set. * * Right now the service method also includes a very primitive debugging mode that * just dumps the raw amf input and output to files. This may change in later versions. * The debugging implementation is NOT thread safe so be aware of file corruptions that * may occur in concurrent environments. */ function service() { //Set the parameters for the charset handler CharsetHandler::setMethod($this->_charsetMethod); CharsetHandler::setPhpCharset($this->_charsetPhp); CharsetHandler::setSqlCharset($this->_charsetSql); //Attempt to call charset handler to catch any uninstalled extensions $ch = new CharsetHandler('flashtophp'); $ch->transliterate('?'); $ch2 = new CharsetHandler('sqltophp'); $ch2->transliterate('?'); $GLOBALS['amfphp']['actions'] = $this->actions; if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); } if (isset($GLOBALS["HTTP_RAW_POST_DATA"]) && $GLOBALS["HTTP_RAW_POST_DATA"] != "") { //Start NetDebug NetDebug::initialize(); error_reporting($GLOBALS['amfphp']['errorLevel']); //Enable loose mode if requested if ($this->_looseMode) { ob_start(); } $amf = new AMFObject($GLOBALS["HTTP_RAW_POST_DATA"]); // create the amf object if ($this->incomingMessagesFolder != NULL) { $mt = microtime(); $pieces = explode(' ', $mt); file_put_contents($this->incomingMessagesFolder . 'in.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf", $GLOBALS["HTTP_RAW_POST_DATA"]); } foreach ($this->filters as $key => $filter) { $filter($amf); // invoke the first filter in the chain } $output = $amf->outputStream; // grab the output stream //Clear the current output buffer if requested if ($this->_looseMode) { ob_end_clean(); } //Send content length header //Thanks to Alec Horley for pointing out the necessity //of this for FlashComm support header(AMFPHP_CONTENT_TYPE); // define the proper header if (Headers::getHeader('serviceBrowser') == true) { //Add the total time header $toAddPos = strpos($output, "СА"); $time = (int) ((microtime_float() - $GLOBALS['amfphp']['startTime']) * 1000); $b = pack("d", $time); // pack the bytes if (AMFPHP_BIG_ENDIAN) { // if we are a big-endian processor $r = strrev($b); } else { // add the bytes to the output $r = $b; } $output = substr($output, 0, $toAddPos) . $r . substr($output, $toAddPos + 8); } //Send expire header, apparently helps for SSL //Thanks to Gary Rogers for that //And also to Lucas Filippi from openAMF list //And to Robert Reinhardt who appears to be the first who //documented the bug //Finally to Gary who appears to have find a solution which works even more reliably $dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days")); header("Expires: {$dateStr} GMT"); header("Pragma: no-store"); header("Cache-Control: no-store"); //else don't send any special headers at all if ($this->outgoingMessagesFolder != NULL) { $mt = microtime(); $pieces = explode(' ', $mt); file_put_contents($this->outgoingMessagesFolder . 'out.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf", $output); } $doCompress = false; $outputCompression = @ini_get("zlib.output_compression"); if (!$outputCompression) { if (strlen($output) > $this->_gzipCompressionThreshold && extension_loaded("zlib") && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE && $this->_enableGzipCompression) { $doCompress = true; ob_start(); ob_start('ob_gzhandler'); } else { header("Content-length: " . strlen($output)); } } print $output; // flush the binary data if ($doCompress) { ob_end_flush(); header("Content-length: " . ob_get_length()); ob_end_flush(); } } else { $versionData = explode("\n", file_get_contents(APP . DS . "plugins" . DS . "cpamf" . DS . "version.txt")); $cpamfVersion = $versionData[count($versionData) - 1]; echo "<p> CpAmf plugin v" . $cpamfVersion . " (CakePHP 1.2)</p>"; echo "<p>amfphp and this gateway are installed correctly. You may now connect " . "to this gateway from Flash.</p>"; if (function_exists("amf_decode")) { echo "<p>AMF C Extension is loaded " . ($GLOBALS['amfphp']['native'] ? "and enabled." : "but disabled") . "</p>"; } echo "<p>Note: If you're reading an " . "old tutorial, it will tell you that you should see a download " . "window instead of this message. This confused people so this is " . "the new behaviour starting from amfphp 1.2.</p><p>" . "<a href='http://www.amfphp.org/docs'>View the amfphp documentation</p>" . "<p><a href='browser'>Load the service browser</a></p>"; echo "<pre>"; } }
/** * The service method runs the gateway application. It turns the gateway 'on'. You * have to call the service method as the last line of the gateway script after all of the * gateway configuration properties have been set. * * Right now the service method also includes a very primitive debugging mode that * just dumps the raw amf input and output to files. This may change in later versions. * The debugging implementation is NOT thread safe so be aware of file corruptions that * may occur in concurrent environments. */ function service() { //Set the parameters for the charset handler CharsetHandler::setMethod($this->_charsetMethod); CharsetHandler::setPhpCharset($this->_charsetPhp); CharsetHandler::setSqlCharset($this->_charsetSql); //Attempt to call charset handler to catch any uninstalled extensions $ch = new CharsetHandler('flashtophp'); $ch->transliterate('?'); $ch2 = new CharsetHandler('sqltophp'); $ch2->transliterate('?'); $GLOBALS['amfphp']['actions'] = $this->actions; if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); } if (isset($GLOBALS["HTTP_RAW_POST_DATA"]) && $GLOBALS["HTTP_RAW_POST_DATA"] != "") { //Start NetDebug NetDebug::initialize(); error_reporting($GLOBALS['amfphp']['errorLevel']); //Enable loose mode if requested if ($this->_looseMode) { ob_start(); } $amf = new AMFObject($GLOBALS["HTTP_RAW_POST_DATA"]); // create the amf object if ($this->incomingMessagesFolder != NULL) { $mt = microtime(); $pieces = explode(' ', $mt); file_put_contents($this->incomingMessagesFolder . 'in.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf", $GLOBALS["HTTP_RAW_POST_DATA"]); } foreach ($this->filters as $key => $filter) { $filter($amf); // invoke the first filter in the chain } $output = $amf->outputStream; // grab the output stream //Clear the current output buffer if requested if ($this->_looseMode) { if ($this->_obLogging !== FALSE) { $this->_appendRawDataToFile($this->_obLogging, ob_get_clean()); } else { ob_end_clean(); } } //Send content length header //Thanks to Alec Horley for pointing out the necessity //of this for FlashComm support header(AMFPHP_CONTENT_TYPE); // define the proper header header("Content-length: " . strlen($output)); //Send expire header, apparently helps for SSL //Thanks to Gary Rogers for that //And also to Lucas Filippi from openAMF list //And to Robert Reinhardt who appears to be the first who //documented the bug //Finally to Gary who appears to have find a solution which works even more reliably if ($this->useSslFirstMethod) { $dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days")); header("Expires: {$dateStr} GMT"); header("Pragma: no-store"); header("Cache-Control: no-store"); } //else don't send any special headers at all if ($this->outgoingMessagesFolder != NULL) { $mt = microtime(); $pieces = explode(' ', $mt); file_put_contents($this->outgoingMessagesFolder . 'out.' . $pieces[1] . '.' . substr($pieces[0], 2) . ".amf", $output); } print $output; // flush the binary data } else { echo "<p>amfphp and this gateway are installed correctly. You may now connect " . "to this gateway from Flash.</p><p>Note: If you're reading an " . "old tutorial, it will tell you that you should see a download " . "window instead of this message. This confused people so this is " . "the new behaviour starting from amfphp 1.2.</p><p>" . "<a href='http://www.amfphp.org/docs'>View the amfphp documentation</p>"; } }
/** * The service method runs the gateway application. It turns the gateway 'on'. You * have to call the service method as the last line of the gateway script after all of the * gateway configuration properties have been set. * * Right now the service method also includes a very primitive debugging mode that * just dumps the raw amf input and output to files. This may change in later versions. * The debugging implementation is NOT thread safe so be aware of file corruptions that * may occur in concurrent environments. */ public function service() { //Set the parameters for the charset handler CharsetHandler::setMethod($this->_charsetMethod); CharsetHandler::setPhpCharset($this->_charsetPhp); CharsetHandler::setSqlCharset($this->_charsetSql); //Attempt to call charset handler to catch any uninstalled extensions $ch = new CharsetHandler('flashtophp'); $ch->transliterate('?'); $ch2 = new CharsetHandler('sqltophp'); $ch2->transliterate('?'); $GLOBALS['amfphp']['actions'] = $this->actions; if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { $GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input'); } $raw_data = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!isset($raw_data[0])) { echo "<p>amfphp and this gateway are installed correctly. You may now connect ", "to this gateway from Flash.</p>"; exit(0); } //Enable loose mode if requested if ($this->_looseMode) { ob_start(); } $amf = new AMFObject($raw_data); // create the amf object foreach ($this->filters as $filter) { $filter($amf); // invoke the first filter in the chain } $output = $amf->outputStream; // grab the output stream //Clear the current output buffer if requested if ($this->_looseMode) { ob_end_clean(); } //Send content length header header('Content-type: application/x-amf'); // define the proper header // write header for no browser cache the amf data header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 86400) . ' GMT'); header("Pragma: no-store"); header("Cache-Control: no-store"); $doCompress = false; $outputCompression = ini_get("zlib.output_compression"); if (!$outputCompression) { if ($this->_enableGzipCompression && strlen($output) > $this->_gzipCompressionThreshold && extension_loaded("zlib") && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE) { $doCompress = true; ob_start(); ob_start('ob_gzhandler'); } else { header("Content-length: " . strlen($output)); } } print $output; // flush the binary data if ($doCompress) { ob_end_flush(); header("Content-length: " . ob_get_length()); ob_end_flush(); } }