Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Profiling PHP @ PHPCon Poland 2016

Profiling PHP @ PHPCon Poland 2016

PHPCon Poland 2016
http://www.phpcon.pl/2016/pl/

Sebastian Grodzicki

October 01, 2016
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Technology

Transcript

  1. log_format foobar '$remote_addr ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent"

    ' '$request_time $upstream_response_time’; access_log /var/log/nginx/access.log foobar; NGINX
  2. PROFILING PHP INCLUSIVE VS EXCLUSIVE TIME function foo()
 {
 $str

    = bar(); return $str; } function foo()
 {
 $str = bar(); return $str; }
  3. PROFILING PHP ASSERTIONS tests: "Application should never hit the DB":

    path: "/.*" assertions: - "metrics.sql.queries.count == 0"
  4. PROFILING PHP ASSERTIONS tests: "Homepage should never call the API":

    path: "/" assertions: - "metrics.http.requests.count == 0"
  5. PROFILING PHP ASSERTIONS tests: "Pages should be fast enough": path:

    "/.*" assertions: - "main.wall_time < 100ms"
  6. BLACKFIRE PHP SDK ▸ composer require blackfire/php-sdk ▸ $blackfire =

    new \Blackfire\Client(); ▸ $probe = $blackfire->createProbe(); ▸ $profile = $blackfire->endProbe($probe);
  7. <?php
 
 use Blackfire\Bridge\PhpUnit\TestCaseTrait;
 use Blackfire\Profile;
 
 class IntegrationTest extends

    \PHPUnit_Framework_TestCase {
 use TestCaseTrait;
 /**
 * @requires extension blackfire
 */
 public function testSomething() {
 $config = new Profile\Configuration();
 $config
 ->assert('metrics.sql.queries.count < 5', 'SQL queries')
 ->assert('metrics.twig.render.count < 3', 'Rendered Twig templates')
 ->assert('metrics.twig.compile.count == 0', 'Twig compilation')
 ;
 }
 }