简体   繁体   English

如何在Windows中安装'posix'

[英]How to install 'posix' in windows

I'm using WAMP server in windows 7 and trying to use posix function in php but it's not working and giving fatal error:undefined function . 我在Windows 7中使用WAMP服务器,并尝试在php中使用posix函数,但它不起作用并给出fatal error:undefined function Now i want to know, how i can install it on windows. 现在我想知道如何在Windows上安装它。

If it's not available for windows how would like to know how to get file owner name by id on Windows, and where can I read about implementing similar posix features on Windows. 如果Windows无法使用它,该如何在Windows上知道如何通过id获取文件所有者的名称 ,以及在哪里可以阅读到有关在Windows上实现类似posix功能的信息。

Obviously, since Windows proper is not a POSIX operating system, you cannot use PHP's POSIX support in a standard WAMP stack. 显然,由于Windows本身不是POSIX操作系统,因此您不能在标准WAMP堆栈中使用PHP的POSIX支持。

The Windows equivalent is PHP's Windows Only Extensions . Windows等同于PHP的Windows Only Extensions This includes support for using .NET classes, which allows you to do most things that any other Windows application can do. 这包括对使用.NET类的支持,该类允许您执行其他Windows应用程序可以执行的大多数操作。

For example, in order to find out the owner of a file, you might use System.IO.File.GetAccessControl as described in the answers to this question . 例如,为了找出文件的所有者,您可以按照此问题的答案中所述使用System.IO.File.GetAccessControl You are likely to find existing questions and answers to address most other needs you might have. 您可能会发现现有的问题和答案,以解决您可能还有的其他大多数需求。

(You may prefer to consider switching to a LAMP stack, on a virtual machine if necessary.) (如果需要,您可能希望考虑切换到虚拟机上的LAMP堆栈。)


Nitpicker's corner: Nitpicker的角落:

Windows 10 provides beta POSIX support via the Windows Subsystem for Linux, and some versions of Windows Server support Interix, another POSIX-based subsystem, but to the best of my knowledge no standard WAMP stack makes either of these directly available from PHP. Windows 10通过用于Linux的Windows子系统提供beta POSIX支持,并且某些版本的Windows Server支持另一个基于POSIX的子系统Interix,但是据我所知,没有标准的WAMP堆栈可直接从PHP中获得这两个组件。

In any case, if you are using OS-specific extensions in the first place it is almost always going to be preferable to use the functionality native to the actual host operating system in order to avoid unnecessary complications. 无论如何,如果您首先使用的是特定于操作系统的扩展,那么为避免不必要的复杂性,几乎总是最好使用实际主机操作系统的本机功能。 For example, retrieving the WSL owner ID for a file on an NTFS partition potentially loses information, since Linux only supports 32-bit IDs, very different to Windows SIDs. 例如,检索NTFS分区上文件的WSL所有者ID可能会丢失信息,因为Linux仅支持与Windows SID完全不同的32位ID。

Disclaimer: I have no idea what WSL actually does in such cases; 免责声明:我不知道WSL在这种情况下实际上会做什么。 it is entirely possible that in some scenarios this would not present an actual problem. 在某些情况下,这很可能不会带来实际问题。 My point is merely that having to find out how this works in order to make sure it will meet your needs is an unnecessary complication compared to either using the functionality native to Windows, or running your service on a genuine Linux host if that is your preference. 我的观点仅仅是,与使用Windows固有的功能或在真正的Linux主机上运行服务(如果您愿意)相比,必须找出它的工作方式以确保它能够满足您的需求是不必要的麻烦。 。

This is not as simple as in Linux, and posix is not trivially used in Windows (as the plethora of comments below suggest). 这并不像在Linux中那样简单,并且posix在Windows中也很少使用 (如下面的大量注释所示)。 There is a POSIX 1.0 implementation invoked by the posix subsystem , though this was deprecated since Windows 8. Another option is SFU (Service for Unix) which is also deprecated (removed?) since Win 8, though a new Windows 10 bash! 尽管从Windows 8开始不推荐使用posix子系统调用POSIX 1.0实现,但是另一个选择是SFU(Unix服务),从Win 8开始也不再推荐(删除?),尽管使用了新的Windows 10 bash! is going to replace it - I'm not familiar enough to know how easily you can use it but it may bring a change. 将要替换它-我还不熟悉您是否可以轻松使用它,但是它可能会带来变化。 Finally there are 3'd party application you can use to mimic the UNIX environment like Cygwin, but I think that's a bit much to expect your server to use them from an optimization point of view. 最后,您可以使用3d第三方应用程序来模仿UNIX环境(例如Cygwin),但是我认为从优化的角度来看,您的服务器可以使用它们来做些事情。

In my opinion your best bet is invoking Native Windows commands through C++.Your question is a bit too vague in my opinion so I'll only address only your example. 我认为您最好的选择是通过C ++调用Windows本机命令。我认为您的问题太含糊了,因此我只讲您的示例。 Basically what you need are: 基本上,您需要的是:

The following example uses the GetSecurityInfo and LookupAccountSid functions to find and print the name of the owner of a file 下面的示例使用GetSecurityInfoLookupAccountSid函数查找并打印文件所有者的名称。

This is taken from the msdn docs which you need to get acquainted with, and contains many native Windows APIs. 该摘自您需要熟悉的msdn文档 ,并且包含许多本机Windows API。 In there you will find a long example of what you need (for the example - this is a full implementation using the above functions, so just copy paste and compile. 在该处,您会找到一个很长的需求示例(对于该示例-这是使用上述功能的完整实现,因此只需复制粘贴并进行编译即可)。

EDIT - PHP 编辑-PHP

Regarding PHP, there is no clean solution for getting the user ID. 关于PHP,没有干净的解决方案来获取用户ID。 I would suggest calling a small C++ exe implemented as above if you need this, through the exec function or some such. 我建议您通过exec函数或类似的函数调用一个如上所述实现的小型C ++ exe。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM