我在Windows命令行輸入命令:C:\wamp\bin\php\php5.2.6\php.exe getXml.php以執行php文件。
出現錯誤:Fatal error: Call to undefined function socket_create() in C:\wamp\www\getXml.php on line 13
網上搜了挺多論壇上的Q&A貼子,答案基本上是:
1. 找到php.ini,看 extension=php_sockets.dll 擴展是否打開,將前面的注釋; 刪去。
2. 看phpInfo()顯示的內容里,socket模塊是否為enable;
還有說是少了一些dll文件,但是下了php4ts.dll、php5ts.dll、php_mime_magic.dll並將它們拷到目錄C:/Windows/system32下,並確認php目錄下的ext文件夾下存在php_sockets.dll文件,結果還是沒有解決問題。
解決方案: 這是在一個英文論壇上看到的方案,經過實踐證明是可行的。
原文是:
The command prompt uses a different php.ini file to the apache server.
The Apache php.ini file is accessible via the taskbar icon, and is located at:
X:\WAMP INSTALL DIR\Apache2\bin\php.ini
The command prompt php.ini file is located at:
X:\WAMP INSTALL DIR\php\php.ini
Once I’d enabled sockets in this file, by uncommenting the line:
extension=php_sockets.dll
and restarted the server, everything worked great.
在兩個目錄下都有php.ini 我們使用wamp 的管理界面直接修改的php.ini是位於:
C:\wamp\bin\apache\apache2.2.8\bin\php.ini 下的(因個人安裝的目錄而不同),事實證明我確實在這個php.ini文件中修改了php_sockets.dll前面的注釋符號”;” ,但為什么沒有用呢?
那是因為在另外一個目錄: C:\wamp\bin\php\php5.2.6\php.ini(也因個人的安裝而不同)中的擴展沒有修改, 而我們只需修改它,就行了, 再拷一份修改后的php,ini文件到目錄C:\Windows\目錄下。