1

Came across this thread, how to install posix in php, but it's not 2011 anymore. Latest versions of Windows are said to have 100% POSIX support. What about a PHP wrapper?

I need the equivalent of yum install php-process, a .dll or something.

Community
  • 1
  • 1
Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • I think we still in 2011 (http://php.net/manual/en/intro.posix.php); Windows can provide POSIX support, but PHP doesn't provide the extension for windows. – Gabriel Heming Nov 11 '16 at 17:52
  • I think saying 100% POSIX support is an exaggeration, [the WSL is still a beta product](https://blogs.msdn.microsoft.com/wsl/2016/07/08/bash-on-ubuntu-on-windows-10-anniversary-update/) and can be expected to have issues. Regardless, I would *guess* that the most sensible option if you wanted POSIX via PHP would be to install Ubuntu's PHP distribution rather than a Windows one. – Harry Johnston Nov 11 '16 at 23:21

1 Answers1

0

Python supports all POSIX operations the operating systems do, so the easiest workaround is to shell_exec python scripts. The plus side is that you don't break platform independency with this.

To take it further, this is how I created the missing funcionality:

function fdopen($fd, $mode, $buffersize){
    return shell_exec("
          python -c 'import os; print os.fdopen(".$fd.",".$mode.",".$buffersize.")'
    ");
}

Exception handling is the catch, however. You have to catch all exceptions on the Python side, and output something by which you can identify the exception in PHP.

Every function can be implemented following the analogy of this. Even though it's a pain in the ass, in general I was fine with like 4-5 different syscalls for this project, so it's not a big deal either. But you need Python :)

Rápli András
  • 3,869
  • 1
  • 35
  • 55
  • Um ... that code shouldn't work, because file descriptors aren't inheritable on Windows. Unless Python's fdopen actually opens file *handles* rather than file *descriptors*, I guess? (I'd find that surprising, the documentation certainly makes it look like they really are talking about file descriptors. But I can't rule it out.) – Harry Johnston Nov 14 '16 at 20:49
  • I think you're right. (I didn't need fdopen for the code, just made it up for an example) – Rápli András Nov 14 '16 at 22:52