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.

如果我在Windows上編寫PHP(php5,如果它很重要),Apache就像在另一個操作系統和Apache上編寫PHP一樣?我不是指文件路徑之類的東西。謝謝。

7 个解决方案

#1


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.

您可能會在某個服務器中使用PHP作為模塊時遇到一些障礙,另一個使用它通過fcgi。以相同方式配置的兩個Apache將以相同的方式運行。

#2


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包可以非常廣泛地包含在默認安裝中。你需要確保在對面平台的開發盒上測試你的應用程序,以確保你已經編譯/添加了所有必需的庫,或者你會從一個看起來很正常的應用程序中得到一些很好的致命錯誤。

#3


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.

只要你不執行系統命令或使用無效的文件路徑,大多數事情都應該沒有問題。我一直在使用PHP一段時間,在Windows機器上開發然后將其移到Linux機器上,我想不出任何我遇到過麻煩的事情。

#4


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.

也就是說,關於在Windows上不起作用的內容,PHP手冊已有詳細記錄。

#5


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

鑒於PHP只是一種語言,這應該沒關系。無論走到哪里都應該是一樣的。

#6


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

是的......設置它可能會有所不同,但它的用法與腳本語言相同。

#7


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.

有一些差異,正如其他用戶所指出的那樣(我不會重復那些,已經有很好的答案;最煩人的一點是在Windows下的文件名中不區分大小寫,恕我直言),所以如果你使用Linux服務器進行部署你在生產中的網站,偶爾在Linux上測試它可能是有用的。

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更常用。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/07/21/72fd170682bcb983be839061514b99d2.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com