Chapters
-
Course Code
Compatible PHP versions: ^7.1.3
Compatible PHP versions: ^7.1.3
- This Video
- Subtitles
- Course Script
Production Profile: Cache Stats & More Recommendations
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
We just profiled our first page on production, which is using the Blackfire Server Id and Token for the environment we created.
Profiles Belong to the Environment
Go to https://blackfire.io, click "Environments", open our new environment... and click the "Profiles" tab. Yep! Whenever anyone creates a profile using this environment's credentials, it will now show up here: the profile belongs to this environment. We haven't invited any other users to this environment yet, but if we did, they would immediately be able to access this area and trigger new profiles with their browser extension.
If you go to back to https://blackfire.io to see your dashboard, the new profile also shows up here. But that's purely for convenience. The profile truly belongs to the environment. You can even see that right here. But Blackfire places all profiles that I create on this page... to make life nicer.
Click the profile to jump into it. Of course... this looks exactly like any profile we created on our local machine. But it does have a few differences.
Caching Information
Hover over the profile name to find... "Cache Information". We talked about this earlier: it shows stats about various different caches on your server and how much space each has available. Now that we're profiling on production, this data is super valuable!
For example, if your OPcache filled up, your site would start to slow down considerably... but it might not be very obvious when that happens. It's not like there are alarms that go off once PHP runs out of OPcache space. But thanks to this, you can easily see how things really look, right now, on production. If any of these are full or nearly full, you can read documentation to see which setting you need to tweak to make that cache bigger.
Quality & Security Recommendations
The other thing I want to show you is under "Recommendations" on the left. There are 3 types of recommendations... and we have one of each: the first is a security recommendation, the second is a quality recommendation and the third a performance recommendation. Only the performance recommendations come standard: the other two require an "Add on"... which I didn't have until I started using my organization's plan.
As always, to get a lot more info about a problem and how to fix it, you can click the question mark icon.
Converting Recommendations into Assertions
One of my favorite things about recommendations is that you can easily convert any of these into an assertion. If you click on assertions, you'll remember that we created one "test" that said that every page should have - at maximum - one HTTP request.
We configured that inside of our .blackfire.yaml
file: we added tests
, configured this test to apply to every URL, and leveraged the metrics system to write an expression.
Back on the recommendations, click to see more info on one of these... then scroll down. Every recommendation contains code that you can copy into your .blackfire.yaml
file to convert that recommendation into a test... or "assertion".
That might not seem important right now... because so far, it looks like doing that would simply "move" this from a "warning" under "Recommendations" to a "failure" under "Assertions"... which is cool... but just a visual difference.
But! In a few minutes, we'll discover that these assertions are much more important than they seem. To see why, we need to talk about the key feature and superpower of environments: builds.
Comments
"Houston: no signs of life"
Start the conversation!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": "^7.1.3",
"ext-ctype": "*",
"ext-iconv": "*",
"blackfire/php-sdk": "^1.20", // v1.20.0
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // v1.8.0
"doctrine/doctrine-bundle": "^1.6.10|^2.0", // 1.11.2
"doctrine/doctrine-migrations-bundle": "^1.3|^2.0", // v2.0.0
"doctrine/orm": "^2.5.11", // v2.6.4
"phpdocumentor/reflection-docblock": "^3.0|^4.0", // 4.3.2
"sensio/framework-extra-bundle": "^5.4", // v5.5.1
"symfony/console": "4.3.*", // v4.3.10
"symfony/dotenv": "4.3.*", // v4.3.10
"symfony/flex": "^1.9", // v1.21.6
"symfony/form": "4.3.*", // v4.3.10
"symfony/framework-bundle": "4.3.*", // v4.3.9
"symfony/http-client": "4.3.*", // v4.3.10
"symfony/property-access": "4.3.*", // v4.3.10
"symfony/property-info": "4.3.*", // v4.3.10
"symfony/security-bundle": "4.3.*", // v4.3.10
"symfony/serializer": "4.3.*", // v4.3.10
"symfony/twig-bundle": "4.3.*", // v4.3.10
"symfony/validator": "4.3.*", // v4.3.10
"symfony/webpack-encore-bundle": "^1.6", // v1.7.2
"symfony/yaml": "4.3.*", // v4.3.10
"twig/extensions": "^1.5" // v1.5.4
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.2", // 3.2.2
"easycorp/easy-log-handler": "^1.0.7", // v1.0.9
"fzaninotto/faker": "^1.8", // v1.8.0
"symfony/browser-kit": "4.3.*", // v4.3.10
"symfony/css-selector": "4.3.*", // v4.3.10
"symfony/debug-bundle": "4.3.*", // v4.3.10
"symfony/maker-bundle": "^1.13", // v1.14.3
"symfony/monolog-bundle": "^3.0", // v3.5.0
"symfony/phpunit-bridge": "^5.0", // v5.0.3
"symfony/stopwatch": "4.3.*", // v4.3.10
"symfony/var-dumper": "4.3.*", // v4.3.10
"symfony/web-profiler-bundle": "4.3.*" // v4.3.10
}
}