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

Profiling PHP @ phpCE Prague 2018

Profiling PHP @ phpCE Prague 2018

You cannot improve what you cannot measure. That's why profiling applications should always be the first step before trying to improve its performance. Learn how to spot your applications' bottlenecks and how to adopt profiling into your developer pipeline.

Sebastian Grodzicki

October 27, 2018
Tweet

More Decks by Sebastian Grodzicki

Other Decks in Programming

Transcript

  1. phpinfo(); Sebastian Grodzicki
 • CTO at SHOWROOM • PHP developer

    for 15+ years • #perfmatters !@sebgrodzicki
  2. tests:
 
 "Application should never hit the DB":
 path: "/.*"


    assertions:
 - "metrics.sql.queries.count == 0"
 
 
 "Homepage should never call the API":
 path: "/"
 assertions:
 - "metrics.http.requests.count == 0"
 
 
 "Pages should be fast enough":
 path: "/.*"
 assertions:
 - "main.wall_time < 100ms"
 .blackfire.yml
  3. public function getSingleMetaForChannel(string $path): SeoMeta
 {
 
 $data = $this->client->getSingleMetaForChannel(null,

    $path);
 
 
 if (isset($data[$path])) {
 return SeoMeta::createFromSdk($data[$path]);
 } 
 throw new NotFoundException("Meta for path ${path} not found");
 } SeoRepository.php
  4. <?php declare(strict_types=1);
 
 namespace Repository;
 
 use ValueObject\SeoMeta;
 
 interface

    SeoRepositoryInterface
 {
 public function getSingleMetaForChannel(string $path): SeoMeta;
 } SeoRepositoryInterface.php
  5. public function getSingleMetaForChannel(string $path): SeoMeta
 {
 
 $options = [


    'lang' => self::MAP_CHANNEL_LOCALE[$this->channel],
 'orderings' => '[document.last_publication_date desc]',
 ];
 
 
 $document = $this->client->findOneByPath(
 'seo__content',
 $path,
 $options
 );
 
 
 if (null === $document) {
 throw new NotFoundException("Meta for path {$path} not found");
 }
 
 
 return new SeoMeta($document);
 } PrismicSeoRepository.php
  6. <?php
 
 $url = 'https://2018.phpce.eu/en/';
 $html = \file_get_contents($url);
 $length =

    \strlen($html);
 
 echo \number_format($length) . PHP_EOL; phpCE.php
  7. $ blackfire run php phpCE.php
 
 880,988
 
 Blackfire Run

    completed
 Graph URL https://blackfire.io/profiles/3b82e363-91a6-4807- b03a-4e259a254b98/graph
 No tests! Create some now https://blackfire.io/docs/ cookbooks/tests
 No recommendations
 
 Wall Time 418ms
 I/O Wait 394ms
 CPU Time 24.1ms
 Memory 1MB
 Network 394ms 1MB 1rq
 SQL n/a n/a CLI