PHP code example of roadrunner-php / laravel-bridge
1. Go to this page and download the library: Download roadrunner-php/laravel-bridge library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roadrunner-php / laravel-bridge example snippets
'providers' => [
// ... other providers
Spiral\RoadRunnerLaravel\Queue\QueueServiceProvider::class,
],
use Spiral\Grpc\Client\ServiceClientProvider;
use App\Grpc\EchoServiceInterface;
use App\Grpc\EchoRequest;
class GrpcController extends Controller
{
public function callService(ServiceClientProvider $provider)
{
/** @var EchoServiceInterface $client */
$client = $provider->get(EchoServiceInterface::class);
$request = new EchoRequest();
$request->setMessage('Hello from client!');
$response = $client->Echo($request);
return $response->getMessage();
}
}
namespace App\Workers;
use Spiral\RoadRunnerLaravel\WorkerInterface;
use Spiral\RoadRunnerLaravel\WorkerOptionsInterface;
class CustomWorker implements WorkerInterface
{
public function start(WorkerOptionsInterface $options): void
{
// Your worker implementation goes here
// This method should handle requests from the RoadRunner server
}
}
return [
// ... other configuration options ...
'workers' => [
// Existing workers
Mode::MODE_HTTP => HttpWorker::class,
Mode::MODE_JOBS => QueueWorker::class,
// Your custom worker for a custom or built-in plugin
'custom_plugin' => \App\Workers\CustomWorker::class,
],
];