PHP for Windows與Linux,Mac等相同嗎?

[英]Is PHP for Windows the same as Linux, Mac, etc.?

If I write PHP (php5 if it matters) on Windows and Apache is the same as writing PHP on another OS and Apache? I do not mean things like file paths. Thank you.


7 个解决方案


Mostly, but you have a few things to watch out:


  • Under *nix systems path names are case-sensitive, not under Windows.
  • 在* nix系統下,路徑名稱區分大小寫,而不是Windows。

  • Under *nix systems, the path separator is /. Under Windows it is \, but PHP translates / automatically. Either use the DIRECTORY_SEPARATOR constant or always use /.
  • 在* nix系統下,路徑分隔符是/。在Windows下它是\,但PHP會自動翻譯。使用DIRECTORY_SEPARATOR常量或始終使用/。

  • Under *nix systems, the path traversal schema is different. There is no such thing as a drive letter. There are mount points instead.
  • 在* nix系統下,路徑遍歷模式是不同的。沒有驅動器號這樣的東西。而是有掛載點。

  • Under *nix systems, file permissions are more strict than on Windows by default.
  • 在* nix系統下,默認情況下,文件權限比Windows嚴格。

  • Some functions are not available under Windows or behave differently. These are mostly for low-level functions (memory status, system status). Refer to the PHP documentation.
  • 某些功能在Windows下不可用或行為不同。這些主要用於低級功能(內存狀態,系統狀態)。請參閱PHP文檔。

  • If you are using exec() or any other similar function, the commands won't be the same. Refer to your system documentation.
  • 如果您使用的是exec()或任何其他類似的函數,則命令將不相同。請參閱系統文檔。

About Apache:

You might hit some snags at some point in one server uses PHP as a module and the other one uses it via fcgi. Two Apache configured the same way will behave the same way.



I'm going to mark this as community wiki, as I'm just copying and pasting my answer from another very similar thread:


Almost, but not quite. There are a couple of things you have to watch out for.


1) File names: Windows is a case-insensitive operating system. If you create a file Foo.php, you can include it using include('Foo.php') OR include('foo.php'). When you move your project to Linux/Unix, this will break if you don't have the right case.

1)文件名:Windows是不區分大小寫的操作系統。如果你創建一個文件Foo.php,你可以使用include('Foo.php')或include('foo.php')來包含它。當您將項目移動到Linux / Unix時,如果您沒有正確的案例,這將會中斷。

2) There are some language-specific platform differences, generally when it comes to something that relies on integrated OS functionality. These rarely come up, but you might run into them occasionally. For example, the checkdnsrr() function didn't exist in Windows PHP until version 5.3.0.

2)存在一些特定於語言的平台差異,通常涉及依賴於集成OS功能的東西。這些很少出現,但偶爾會遇到它們。例如,在版本5.3.0之前,Windows PHP中不存在checkdnsrr()函數。

3) Installs. The PHP packages you get for Linux/Unix can very widely in what they include in a default install compared to Windows. You need to make sure to test your app on a development box of the opposite platform just to be sure you have all the required libraries compiled/added in, or you'll get some nice fatal errors from an otherwise normal looking app.

3)安裝。與Windows相比,您在Linux / Unix中獲得的PHP包可以非常廣泛地包含在默認安裝中。你需要確保在對面平台的開發盒上測試你的應用程序,以確保你已經編譯/添加了所有必需的庫,或者你會從一個看起來很正常的應用程序中得到一些很好的致命錯誤。


As long as you don't exec system commands or use invalid file paths, most things should port over no problem. I've been using PHP for a while now, developing on a Windows machine and then moving it over to a Linux box, and I can't think of anything that I had trouble with.



The correct answer is: "it depends".


For the most part PHP will function the same on any operating system. There are quite a few caveats though, typically there are functions that just plain don't work on windows. (e.g. getrusage()). Finding windows libraries for PHP are also rather difficult sometimes, since the death of pecl4win (a site containing windows compilations of all the PECL libraries). This makes adding things like APC (Alternative PHP Cache) quite a chore.

在大多數情況下,PHP在任何操作系統上的功能都相同。但是有很多注意事項,通常有些功能在Windows上不起作用。 (例如getrusage())。尋找PHP的Windows庫有時也很困難,因為pecl4win(一個包含所有PECL庫的Windows編譯的站點)的死亡。這使得添加像APC(Alternative PHP Cache)這樣的東西非常繁瑣。

That said, the PHP manual is well documented with regards to what doesn't work on windows.



It shouldn't matter given that PHP is just a language. Should be the same wherever you go.



Yeah ... Setting it up might be a little different but its usage is the same as it is a scripted language.



There are some differences, as other users noted (I won't repeat those, there are already great answers ; the most annoying point is case-insensivity in files names under windows, IMHO), so if you are using a Linux server to deploy you site in production, it might be useful to test it on Linux once in a while.


If you don't want to install Linux on your machine, and have a powerful enough computer (at least 2 cores, and 2 GB RAM, I'd say), you can use a Virtual Machine, with one of those software (both are free) :

如果您不想在您的計算機上安裝Linux,並且擁有足夠強大的計算機(至少2個核心和2 GB RAM,我會說),您可以使用虛擬機和其中一個軟件(兩者都使用)免費的) :

It'll also help you learn some basics about Linux -- which is not a bad thing to know if you are planning on doing PHP development professionnally, as Linux is far more used than Windows, when it comes to PHP webservers.

它還可以幫助您學習有關Linux的一些基礎知識 - 如果您計划專業地進行PHP開發,這不是一件壞事,因為在PHP Web服務器方面,Linux比Windows更常用。



粤ICP备14056181号  © 2014-2021