blackfireio / php-sdk

The Blackfire PHP SDK
https://blackfire.io
MIT License
150 stars 22 forks source link

Documentation & usage #51

Closed p4veI closed 3 years ago

p4veI commented 3 years ago

Hello, I'm confused from the documented configuration of Blackfire tools & options that are included here in this repository vs. what is included in the official documentation at https://blackfire.io/docs/php/configuration

Especially by this warning here: WARNING: This code should only be used when installing the Blackfire PHP extension is not possible.

I have blackfire configured on the server where my application runs & also installed the PHP extension since it's possible. But as I understand from this warning if I installed the blackfire php extension and should not use this SDK, how do I make blackfire probe profile a certain part of my code without instantiating the probe at a specific place in the code?

Is the PHP extension intended to use with e.g. the browser extension or how should I enable profiling now?

Consider this example..

I have a symfony app and want to profile run on certain endpoint of my app - e.g. I was meaning to include the configured client in the controller's constructor call the createProbe method - which enables the profiling and returns Probe, I have my code executed and before I return the response I call the endProbe method with the Probe instance and end profiling. and return response. This creates a profile in the web interface which I can examine.

Is this considered a correct usage?

Note this means I'm using both my php extension as well as the php sdk.

The official documentation does not mention anything about not using the SDK along with PHP extension.

lolautruche commented 3 years ago

Hello @p4veI

The PHP SDK is not a substitute to the PHP extension. It enables you to programmatically create profiles and builds. There is indeed a legacy class for PHP 5.2, as the PHP extension is only available as of PHP 5.3.

I have a symfony app and want to profile run on certain endpoint of my app - e.g. I was meaning to include the configured client in the controller's constructor call the createProbe method - which enables the profiling and returns Probe, I have my code executed and before I return the response I call the endProbe method with the Probe instance and end profiling. and return response. This creates a profile in the web interface which I can examine.

This looks like a correct programmatic creation of a profile, yes. However, be careful not do trigger this on every request as you will:

  1. Add an overhead for every requests
  2. Quickly reach the API limit (100 profiles/hour - 1000 profiles/day).

You will find the documentation for the SDK here: https://blackfire.io/docs/php/integrations/sdk

lolautruche commented 3 years ago

If you have more questions, please consider using https://support.blackfire.io (using the chat). You may also send an email to support@blackfire.io