sveneld opened a new pull request, #3464:
URL: https://github.com/apache/thrift/pull/3464
Memoize PHP capability probes that previously ran on every hot call.
**Changes:**
- `TBinarySerializer::serialize` / `deserialize` —
`function_exists('thrift_protocol_{write,read}_binary')` was called on every
invocation. Now cached via static `?bool` flags + `hasAcceleratedWrite()` /
`hasAcceleratedRead()` helpers using the null-coalescing assignment (`??=`)
operator.
- `TSocket::open` — `function_exists()` was called twice per `open()` to
detect the sockets extension. Cached via `hasSocketsExtension()` helper.
- `TSocketPool` — replaces per-instance `$useApcuCache` property with static
`$hasApcuCache` + `hasApcuCache()` helper for consistency. APCu availability is
a process-level property, not per-pool.
Each helper performs the check at most once per PHP process. Pure
optimization — no behavior change.
**Tests:**
- Reset the static caches in `setUp()` of `TBinarySerializerTest`,
`TSocketTest`, `TSocketPoolTest` via reflection so the mocked `function_exists`
is re-evaluated per test method (otherwise the cache would persist across tests
in a single PHPUnit process).
- Register `lib/php/src/ext/thrift_protocol/php_thrift_protocol.stub.php` in
`phpstan.neon` `scanFiles` so PHPStan knows about the C-extension functions
guarded by the new helpers — previously the inline `function_exists()` gave
PHPStan a narrowing hint that the helper now hides.
**Validation (Docker `thrift-php-dev:local`):**
- `phpcs` — 0 errors
- `phpstan` (level 1) — 0 errors
- `phpunit` Unit Suite — 635 tests, 0 failures
- `phpunit` Integration Suite — 108 tests, 0 failures
Part of the umbrella ticket
[THRIFT-5960](https://issues.apache.org/jira/browse/THRIFT-5960) (PHP
modernization).
- [x] Did you create an Apache Jira ticket? —
[THRIFT-5984](https://issues.apache.org/jira/browse/THRIFT-5984)
- [x] PR title follows the pattern "THRIFT-NNNN: describe my issue"
- [x] Squashed to a single commit
- [x] No breaking changes (`TSocketPool::$useApcuCache` was private)
Generated-by: Claude Opus 4.7
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]