Skip to content

Instantly share code, notes, and snippets.

@ayonliu
Created June 12, 2014 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayonliu/433a506a516b6bfe0e70 to your computer and use it in GitHub Desktop.
Save ayonliu/433a506a516b6bfe0e70 to your computer and use it in GitHub Desktop.
How to use hessian in laravel
<?php
/*
| app/start/global.php
|--------------------------------------------------------------------------
| Register The Laravel Class Loader
|--------------------------------------------------------------------------
|
| In addition to using Composer, you may use the Laravel class loader to
| load your controllers and models. This is useful for keeping all of
| your classes in the "global" namespace without Composer updating.
|
*/
ClassLoader::addDirectories(array(
app_path().'/commands',
app_path().'/controllers',
app_path().'/models',
app_path().'/database/seeds',
// add for hessian
app_path().'/hessian',
));
<?php
// app/controllers/HomeController.php
class HomeController extends BaseController {
// method for client to call
function getFile($file)
{
return $file . ' hessian';
//return $file;
}
}
<?php
// app/routes.php
// hessian client
Route::get('/hessian', function()
{
//$fp = fopen(dirname(__FILE__).'/unit_tests/ok.png', "r");
$options = new HessianOptions();
$options->version = 2;
$options->transport = "http";
$url = 'http://localhost/laravel/public/hessianServer';
//echo "Testing in url $this->url<br>";
$proxy = new HessianClient($url, $options);
$fp = 'hello';
$data['fp'] = $fp;
//header('Content-Type: image/png');
// call server method
echo $proxy->getFile($data['fp']);
});
// hessian server
Route::post('/hessianServer', function()
{
$testService = new HomeController();
$server = new HessianService($testService, array('displayInfo' => true));
$server->handle();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment