Marks a callable to be excluded from future tracing-JIT compilation.
What It Does and When to Use It
Blacklist a first-class callable before exercising it. OPcache caches compiled opcodes, JIT may optimize CPU-intensive PHP, while APCu caches application-owned values.
Requirements, Inputs and Expected Behavior
Confirm the runtime, extension, environment variables, and permissions before running the examples in production. PHP 8.4+; already JIT-compiled sections are not retroactively deoptimized.
Example 1: Basic Operation
Blacklist a first-class callable before exercising it.
<?php
function sumNumbers(int $n): int {
return array_sum(range(1, $n));
}
opcache_jit_blacklist(sumNumbers(...));
echo sumNumbers(6);
Example 2: Behavior and Validation
An anonymous Closure can also be excluded from future tracing JIT.
<?php
$callback = static function (int $value): int { return $value * 2; };
opcache_jit_blacklist($callback);
echo $callback(7);
Practical Example: Application Use
Guard a feature introduced in PHP 8.4 when maintaining multi-version code.
<?php
if (function_exists('opcache_jit_blacklist')) {
$transform = static fn (string $s): string => trim($s);
opcache_jit_blacklist($transform);
echo $transform(' checked ');
}
Important Behavior and Edge Cases
The second example highlights: An anonymous Closure can also be excluded from future tracing JIT. The practical example adds: Guard a feature introduced in PHP 8.4 when maintaining multi-version code.
Comparison with Related Approaches
| Approach | What changes |
|---|---|
| OPcache, JIT and APCu | OPcache caches compiled opcodes, JIT may optimize CPU-intensive PHP, while APCu caches application-owned values. |
| Choosing safely | Profile application response times and memory under representative traffic before tuning. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Assuming a cache is shared across multiple servers | Confirm process- and host-level cache scope; use a distributed store when needed. |
| Never invalidating cached data | Set a TTL or versioned cache key and test release-time invalidation. |
| Skipping operational constraints | PHP 8.4+; already JIT-compiled sections are not retroactively deoptimized. |
Key Takeaways
- Marks a callable to be excluded from future tracing-JIT compilation.
- Guard a feature introduced in PHP 8.4 when maintaining multi-version code.
- Profile application response times and memory under representative traffic before tuning.