#!/usr/bin/env php op}, {$w->num1}, {$w->num2}})"); switch ($w->op) { case tutorial_Operation::ADD: $val = $w->num1 + $w->num2; break; case tutorial_Operation::SUBTRACT: $val = $w->num1 - $w->num2; break; case tutorial_Operation::MULTIPLY: $val = $w->num1 * $w->num2; break; case tutorial_Operation::DIVIDE: if ($w->num2 == 0) { $io = new tutorial_InvalidOperation(); $io->what = $w->op; $io->why = "Cannot divide by 0"; throw $io; } $val = $w->num1 / $w->num2; break; default: $io = new tutorial_InvalidOperation(); $io->what = $w->op; $io->why = "Invalid Operation"; throw $io; } $log = new SharedStruct(); $log->key = $logid; $log->value = (string)$val; $this->log[$logid] = $log; return $val; } public function getStruct($key) { error_log("getStruct({$key})"); // This actually doesn't work because the PHP interpreter is // restarted for every request. //return $this->log[$key]; return new SharedStruct(array("key" => $key, "value" => "PHP is stateless!")); } public function zip() { error_log("zip()"); } }; header('Content-Type', 'application/x-thrift'); if (php_sapi_name() == 'cli') { echo "\r\n"; } $handler = new CalculatorHandler(); $processor = new CalculatorProcessor($handler); $transport = new TBufferedTransport(new TPhpStream(TPhpStream::MODE_R | TPhpStream::MODE_W)); $protocol = new TBinaryProtocol($transport, true, true); $transport->open(); $processor->process($protocol, $protocol); $transport->close();