Interoperability with the focus on PHP. Some pure PHP details, internal details are making it interesting for regular PHP developers as well as for extension developers.
11. Interoperable PHP
File/process permissions
• UNIX/Linux
• chmod(), chown(), etc.
• process permissions are handled same way as file ones
• Windows
• icacls
• impersonation
• Unmapped UNIX users built-in SID mapping
12. Interoperable PHP
Access time
• ext3, ext4 and others
• noatime,nodiratime in /etc/fstab
• NTFS
• fsutil behavior query DisableLastAccess
• fsutil behavior set DisebleLastAccess 0
13. Interoperable PHP
NTFS streams
C:tmp> echo hello > foo.txt
C:tmp>echo world > foo.txt:bar.txt
C:tmp>dir /r foo.txt
Volume in drive C is SYSTEM
Volume Serial Number is AE0A-76BD
Directory of C:tmp
08/31/2015 11:50 PM 8 foo.txt
8 foo.txt:bar.txt:$DATA
1 File(s) 8 bytes
0 Dir(s) 59,944,050,688 bytes free
16. Interoperable PHP
PHP FS snippet 3
<?php
$f = fopen("file.txt", "w");
var_dump(unlink("file.txt"));
// Windows
Warning: unlink(file.txt): Permission denied in Command line code on line 1
bool(false)
//Linux
bool(true)
17. Interoperable PHP
PHP FS snippet 4
<?php
var_dump(fopen("some/directory", "r"));
// Windows
Warning: fopen(some/directory): failed to open stream: Permission denied in
Command line code on line 1
bool(false)
//Linux
resource(5) of type (stream)
30. Interoperable PHP
64- vs 32-bit in PHP
64-bit
• In general slower
• 9.22337204 × 109 GB
RAM addressable
• 64-bit integers
• LFS
• 64-bit string length
32-bit
• In general faster
• Less than 2 GB RAM
addressable
• 32-bit integers
• 32-bit file operations
• 32-bit string length
31. Interoperable PHP
Types in PHP7
• zend_long for integers
• zend_ulong for numeric hashes
• size_t for string length
• zend_off_t for file offsets
• zend_stat_t for file offsets
Hardware – various hardware existing or needed for a program.
Architecture – how is the hardware put together.
OS – an exact operating system.
Tree above – platform.
Program – actual binary running upon the platform. With PHP - the PHP interpreter.
A cross-platform program can be handled within the same source tree, or with different sources for different platforms. As well many interpreted programming languages supports multiple platforms. Also there are like a dozen platforms within Unix, Linux, Windows.
Access control lists and others vs UNIX permissions.
Unmapped UNIX user example – Samba, NFS, etc.
Atime is usually off by default off windows. On linux depends on a distribution, but most likely is on.
readdir() fileorder can differ not only between platforms, but also depends on filesystems.
symlink() with relative paths is not thread safe, threads could have changed the CWD.
realpath() might show different results depending on platform/OS. Fe case insensitive on Windows, case sensitive on Linux, optional case sensitivity on OSX.
TSC – time stamp counter, a 64-bit register on intel Architectures. The TSC frequency is not assumed to be constant, it is periodically tweaked, that is what the adjtimex system call is for. A user space program/daemon (like NTP and PTP) uses adjtimex to tell Linux how to slew the frequency over time.
A periodic procedure calibrates the TSC frequency and the period is given by the RTC (system clock)? So the change of the TSC counter is compared to an elapsed time of the RTC (system clock). Thus the resulting TSC frequency is calibrated to give exactly one million microseconds/second
PM clock – power management clock rate, might depend on ACPI – advanced configuration and power interface
HPET – high precision event timer
POSIX clock – standard for implementing and representing time sources, abstraction layer
Usleep() … system call, posix monotonic clock vs performance timer … mention hrtime here
Timeout counting on Linux doesn’t include time spent for syscalls, f.e. for sleep(). On Windows, timer is running in parallel with the PHP script execution.
Opcache ASLR issue on Windows
Various shared memory issues in NTS builds.
Under Linux shared memory is accessible between processes, Windows it's not always the case. Especially it's to mention for ACRL cases.
Like SQL query cache.
PGO – profile guided optimization
LTO – link time optimization
FDO – feedback directed optimization
Windows x64 no inline ASM
PHP targets SSE2 on x86
make clean
make -j4 prof-gen
# run training scripts
make prof-clean
make -j4 prof-use
configure –enable-pgi
nmake
# run training
nmake clean
./configure –enable-pgo
nmake
Big file uploads count for LFS as well.
A combination of 32-bit processes running on 64-bit OS – the processes are still a bit slower that on a native 32-bit OS, but can use their 2GB memory limits.
Stack pointer
Registers
Scheduling properties (such as policy or priority)
Set of pending and blocked signals
Thread specific data.
Shared file descriptors and co.
Most of the dead stuff was removed in PHP7, embed can be used in any userspace programs, also used in several servers, fe NaviServer (former AOLserver).
Classic model when learning socket programming.
A good example for cross platform thread locking is APC. Cross-platform threading is possible with pthreads.
And mention globals in php7 are TLS based as well, but actually it’s a bigger topic which can turn into a sleeping pill
In php7 it opens the door for better binary compatibility, because in many cases a thread specific global variable can be used instead of extending the extension globals structres. This can be a big salvation for bug fixes in the middle of some stable release.
TS less robust, more sparse servers can be started.
mail() isn’t thread safe until PHP7 on windows
Locale is not thread safe
mt_rand() might work not in the range expected
symlink vs. junction
Getenv()/putenv() isn’t thread safe. Fe #69636 . This has an alternative threaded API on windows, but no chance on linux.