Doc #79439 [Com]: ZTS chdir() does not really change the CWD

From: Date: Wed, 17 Jun 2020 18:34:09 +0000
Subject: Doc #79439 [Com]: ZTS chdir() does not really change the CWD
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-17654@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79439&edit=1 ID: 79439 Comment by: alexdowad@php.net Reported by: nesk at xakep dot ru Summary: ZTS chdir() does not really change the CWD Status: Re-Opened Type: Documentation Problem Package: Documentation problem Operating System: Win32/Linux/MacOS PHP Version: 7.4.4 Block user comment: N Private report: N New Comment: Just opened a PR to doc-en to warn about this behavior in the manual: https://github.com/php/doc-en/pull/121 I wonder if it should also be documented in the page for chroot()? Previous Comments: ------------------------------------------------------------------------ [2020-04-01 11:22:21] cmb@php.net > However, it may make sense to change the working directory > during calls to the FFI methods? I don't think so. Another thread may change the CWD for another FFI call, and FFI calls may take very long (an FFI call may start an event loop which calls back to PHP functions). > Maybe its worthwhile to correct the documentation, adding > information that the FFI and the ZTS are incompatible? The CWD behavior is not specific to FFI, but affects PHP extensions as well. I agree, though, that it might be worthwhile to be documented. ------------------------------------------------------------------------ [2020-04-01 11:09:48] nesk at xakep dot ru P.S. You say "dont use such libraries", yes, this is an argument. But in this case, ZTS is simply impossible to use when working with the FFI, because almost every library has dependencies that we should be able to manage. Maybe its worthwhile to correct the documentation, adding information that the FFI and the ZTS are incompatible? Or add a warning that by having ZTS you lose the ability to influence the behavior of FFI? ------------------------------------------------------------------------ [2020-04-01 11:04:02] nesk at xakep dot ru I understand that the ZTS isolates the global state. However, it may make sense to change the working directory during calls to the FFI methods? Thus, before any call to the FFI method, we will change it, and after the call, return it back. And because ZTS mode uses a local variable to store the working directory, so we won’t break anything, because getcwd() will return a value from a local variable instead of "GetCurrentDirectory". ------------------------------------------------------------------------ [2020-03-31 16:54:30] cmb@php.net In ZTS mode, chdir() does not actually change the current working directory, because there is only one CWD per process (not per thread). Instead it merely stores the directory path internally, and uses that whenever a relative file path is passed to a PHP function. Functions in an external library are usually not aware of that; especially, GetCurrentDirectory() or getcwd(3) don't know about PHP's virtual CWD. There is nothing we can do about that. So either don't use such libraries, or use NTS builds. ------------------------------------------------------------------------ [2020-03-31 14:32:29] nesk at xakep dot ru P.S. Related issue: https://github.com/SerafimArts/opengl-demo/issues/3 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=79439 -- Edit this bug report at https://bugs.php.net/bug.php?id=79439&edit=1

« previous php.doc.bugs (#17654) next »