Laravel Vapor
How to make Inspector works on Laravel Vapor.
Inspector requires two natives PHP functions (proc_open, proc_close) to send monitoring data to the remote API.
But a serverless environment has different default settings than a normal LAMP server. So the integration in the Vapor environment depends on the type of runtime you use.
You can learn more about Vapor runtimes in this official video lesson.
Use Docker runtime (recommended)
Docker based runtimes offer much more control over the execution environment, so you can deploy applications up to 10GB in size and allow you to install additional PHP extensions or libraries.
In order to use a Docker image instead of the Vapor native runtimes, set the runtime
configuration option to docker
within your vapor.yml
file:
Learn more about Docker runtime in Vapor.
To make Inspector works you must be sure that the current PHP installation in the Docker image has proc_open, and proc_close native functions enabled.
The default Docker runtime should have these functions enabled by default. In alternative you need to create a custom php.ini
file in your project root directory with these two functions not listed in the disable_functions parameter:
Add the entry below in your environment .Dockerfile
to override the default php.ini
configuration:
Now you can continue installing the library as usual: https://docs.inspector.dev/guides/laravel/installation
Use Vapor native runtimes
The AWS standard serverless environment has the proc_open and proc_close functions disabled by default. So Inspector isn’t able to send data to the inspection API with the standard transport class included in the package.
In a normal server environment you can enable these functions changing the php.ini settings, but Vapor native runtimes currently doesn't provide a way to overwrite this configuration during deployment, so you can't enable them.
Set a custom transport
The design of the Inspector package allows developers to inject a custom transport implementation at runtime. Add the code below in the boot method of your AppServiceProvider
:
The callback will receive an instance of the Inspector\Configuration
class, that contains the Ingestion Key, the URL of our remote API, and all other information needed to build the appropriate HTTP call.
QueueTransport implementation
To keep the data sending process “asynchronously” the QueueTransport class should schedule a job to send monitoring data in background:
SendInspectorChunkJob receives the data in its constructor to be sent when the job is scheduled for execution. Here is the implementation of the Job:
Avoid the infinite loop
Finally we must inform Inspector to ignore the SendInspectorChunkJob from monitoring. Otherwise when the job is executed it will run a new transaction itself that generates another job and so on… the infine loop start.
Inspector provides a configuration property to specify the job classes that you want to exclude from monitoring.
Publish the inspector config file if you haven't already done, using the command below:
Now you should have the inspector.php
file in your config directory.
Add the SendInspectorChunkJob class to the "ignore_jobs" array:
Consider to switch to Docker runtime in order to use the built in transport method.
Test and Deploy
You can run the test command to verify everything is well configured before deploy:
Last updated