<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5" -->

---
title: How PHP optimises bytecode | daily.dev
description: A deep dive into how PHP's OPcache extension optimises compiled bytecode beyond simply caching it, based on PHP 8.6. It walks through the fifteen optimizer...
canonical: https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How PHP optimises bytecode | daily.dev
og:description: A deep dive into how PHP's OPcache extension optimises compiled bytecode beyond simply caching it, based on PHP 8.6. It walks through the fifteen optimizer...
og:url: https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5
og:image: https://api.daily.dev/og/posts/yx3UKX0I5.png
og:image:alt: How PHP optimises bytecode
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How PHP optimises bytecode

**[PHPUnit Expert](https://daily.dev/sources/phpunit-expert)** · 24 min read · 2 upvotes · 0 comments

## Summary

A deep dive into how PHP's OPcache extension optimises compiled bytecode beyond simply caching it, based on PHP 8.6. It walks through the fifteen optimizer passes, explains how zend_optimize_script() reverts and redoes pass_two() to rewrite instructions, and shows real bytecode before and after optimization for several example functions. It covers SSA form, sparse conditional constant propagation, dead code elimination, type-specialized opcode handlers, function inlining limitations, and the effect of file boundaries and preloading on cross-function calls. Measurements on a real raytracer project show 14% fewer instructions and 75% fewer temporaries after optimization, translating to roughly 9% faster runtime on the CLI, with the conclusion that opcache.optimization_level and opcache.enable_cli materially affect benchmark comparisons.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://phpunit.expert/articles/how-php-optimises-bytecode.html>

## Questions this post answers

### Does PHP's opcache.enable_cli setting default to on or off?

It defaults to 0 (off). Because of this, PHP test suites run on the command line typically execute unoptimised bytecode unless this setting is explicitly enabled, since opcache.enable alone does not activate OPcache for CLI processes. On one measured test suite this meant 9.91s instead of 8.48s per run, a roughly 14% slowdown.

_Anyone chasing consistent PHP benchmark numbers can track opcache config gotchas like this via daily.dev._

### What does setting opcache.optimization_level to 0 do in PHP?

Setting opcache.optimization_level=0 disables the OPcache bytecode optimiser while leaving the OPcache bytecode cache itself active, since these are two separate mechanisms bundled in the same extension. The optimization_level bit mask defaults to 0x7FFEBFFF, controlling fifteen distinct optimisation passes including constant propagation, dead code elimination, and inlining.

_Developers tuning PHP performance settings can keep tabs on config-level nuances like this through daily.dev._

### Why does PHP's optimiser fail to inline a function once a parameter has a type declaration?

The compiler sets the ZEND_ACC_HAS_TYPE_HINTS flag as soon as any parameter has a declared type, and the inlining pass explicitly excludes functions with that flag set. So a function like epsilon($scale) returning a constant gets inlined, but epsilon(float $scale) does not, and the call returns with its own call frame instead of being eliminated.

_Developers deciding whether to lean on type declarations versus micro-optimisation can follow deep PHP internals coverage on daily.dev._

## Similar posts on daily.dev

- [How PHP generates machine code](https://daily.dev/posts/how-php-generates-machine-code-zwfynbekr) · PHPUnit Expert · 14 upvotes · 1 comments
- [How PHP executes bytecode](https://daily.dev/posts/how-php-executes-bytecode-nmrpdr8hr) · PHPUnit Expert · 19 upvotes · 1 comments
- [PHP 7.4 To PHP 8.6 Benchmarks, PHP 8.6 JIT Performance](https://daily.dev/posts/php-7-4-to-php-8-6-benchmarks-php-8-6-jit-performance-ribwvqfvn) · Phoronix · 10 upvotes · 0 comments
- [PHP Debugger: A Lightweight Xdebug Alternative Built for Speed](https://daily.dev/posts/php-debugger-a-lightweight-xdebug-alternative-built-for-speed-w7zvlhyc6) · Laravel News · 28 upvotes · 1 comments
- [There is NO cache](https://daily.dev/posts/there-is-no-cache-2r2dtwjqr) · Tomas Votruba · 2 upvotes · 0 comments

---

Tags: [#performance](https://daily.dev/tags/performance), [#php](https://daily.dev/tags/php), [#compiler-optimization](https://daily.dev/tags/compiler-optimization)

[View this post on daily.dev](https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How PHP optimises bytecode","url":"https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5"},"datePublished":"2026-08-26T03:54:16.785Z","dateModified":"2026-09-14T08:46:44.970Z","description":"A deep dive into how PHP's OPcache extension optimises compiled bytecode beyond simply caching it, based on PHP 8.6. It walks through the fifteen optimizer...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/01917a612f04f41bf224496c647b3101?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/01917a612f04f41bf224496c647b3101?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"PHPUnit Expert","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"PHPUnit Expert","logo":"https://media.daily.dev/image/upload/s--FMZoysoG--/f_auto,q_auto/v1774964057/logos/phpunit-expert?_a=BAMAMiWQ0","url":"https://daily.dev/sources/phpunit-expert"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"performance,php,compiler-optimization","timeRequired":"PT24M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"PHPUnit Expert","item":"https://daily.dev/sources/phpunit-expert"},{"@type":"ListItem","position":3,"name":"How PHP optimises bytecode"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-php-optimises-bytecode-yx3ukx0i5#faq","mainEntity":[{"@type":"Question","name":"Does PHP's opcache.enable_cli setting default to on or off?","acceptedAnswer":{"@type":"Answer","text":"It defaults to 0 (off). Because of this, PHP test suites run on the command line typically execute unoptimised bytecode unless this setting is explicitly enabled, since opcache.enable alone does not activate OPcache for CLI processes. On one measured test suite this meant 9.91s instead of 8.48s per run, a roughly 14% slowdown. Anyone chasing consistent PHP benchmark numbers can track opcache config gotchas like this via daily.dev."}},{"@type":"Question","name":"What does setting opcache.optimization_level to 0 do in PHP?","acceptedAnswer":{"@type":"Answer","text":"Setting opcache.optimization_level=0 disables the OPcache bytecode optimiser while leaving the OPcache bytecode cache itself active, since these are two separate mechanisms bundled in the same extension. The optimization_level bit mask defaults to 0x7FFEBFFF, controlling fifteen distinct optimisation passes including constant propagation, dead code elimination, and inlining. Developers tuning PHP performance settings can keep tabs on config-level nuances like this through daily.dev."}},{"@type":"Question","name":"Why does PHP's optimiser fail to inline a function once a parameter has a type declaration?","acceptedAnswer":{"@type":"Answer","text":"The compiler sets the ZEND_ACC_HAS_TYPE_HINTS flag as soon as any parameter has a declared type, and the inlining pass explicitly excludes functions with that flag set. So a function like epsilon($scale) returning a constant gets inlined, but epsilon(float $scale) does not, and the call returns with its own call frame instead of being eliminated. Developers deciding whether to lean on type declarations versus micro-optimisation can follow deep PHP internals coverage on daily.dev."}}]}
```

