Skip to content

php-in-php: VmSleepNative — pure PHP sleep()/usleep() without libc FFI (#1492, basic_functions.c) #8922

Description

@PurHur

Category

php-in-php · stdlib · bootstrap

Problem

sleep(), usleep(), time_nanosleep(), and time_sleep_until() VM handlers use VmSleepNative — libc sleep(3)/usleep(3)/nanosleep(2) via FFI. With PHP_COMPILER_DISABLE_FFI=1, sleep(0) returns false and usleep(0) is a no-op that does not match Zend's success semantics — breaking rate-limit tests and bootstrap timing probes.

Prefer a compiled PHP busy-wait or monotonic-clock poll (hrtime pure path) for zero/sub-second delays; keep libc FFI as optional fast path.

php-src reference

Repro

PHP_COMPILER_DISABLE_FFI=1 php bin/vm.php -r 'var_dump(sleep(0));'
PHP_COMPILER_DISABLE_FFI=1 php bin/vm.php -r 'usleep(0); echo "ok\n";'

Observed: bool(false) for sleep(0); usleep silent no-op.

Expected: int(0) for sleep(0); usleep(0) completes without error.

Scope

Path Work
ext/standard/VmSleepNative.php VmSleepPure using VmHrtimeNative / compiled poll
ext/standard/sleep.php, usleep.php, time_nanosleep.php, time_sleep_until.php Fallback routing
JIT/AOT lib/JIT/Builtin/TimeSleepRuntime.php unchanged unless VM parity requires

Done when

  • Repro commands match Zend observable results with FFI disabled
  • php-src-strict: negative args still ValueError
  • Document FFI lines removed or gated behind available()

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions