我尝试从PHP运行java但是即使我使用java可执行文件的绝对路径(C:\ Windows \ System32 \ java.exe)也不能。
我发现问题是由于某种原因,PHP无法访问此文件。我试试:
<?php var_dump(file_exists('C:\Windows\System32\java.exe')); // returns false.
文件实际存在,我(我运行php脚本的用户)有权读取和执行它。 这很奇怪,因为我可以执行notepad.exe和
<?php var_dump(file_exists('C:\Windows\System32\notepad.exe')); // returns true.
有什么想法吗?
php -v
PHP 5.3.27 (cli) (built: Jul 10 2013 20:36:59)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
OS Windows 7 64位
PHPINFO:
phpinfo()函数 PHP版本=&gt; 27年3月5日
System => Windows NT IT8 6.1 build 7601 (Windows 7 Business Edition Service Pack 1) i586
Build Date => Jul 10 2013 20:35:35
Compiler => MSVC9 (Visual C++ 2008)
Architecture => x86
Configure Command => cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql" "--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared" "--with-mcrypt=static" "--disable-static-analyze"
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => C:\Program Files (x86)\PHP\php.ini
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20090626
PHP Extension => 20090626
Zend Extension => 220090626
Zend Extension Build => API220090626,NTS,VC9
PHP Extension Build => API20090626,NTS,VC9
Debug Build => no
Thread Safety => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => disabled
IPv6 Support => enabled
Registered PHP Streams => php, file, glob, data, http, ftp, zip, compress.zlib, compress.bzip2, https, ftps, phar, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp
Registered Stream Socket Transports => tcp, udp, ssl, sslv3, sslv2, tls
Registered Stream Filters => convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, zlib.*, bzip2.*
答案 0 :(得分:0)
如果你想使用php运行java,你必须使用php-jaja-bridge.see这里:http://php-java-bridge.sourceforge.net/pjb/
获取更多帮助,请看: http://darrylclarke.com/2008/03/04/installing-php-java-bridge-on-ubuntu/
答案 1 :(得分:0)
建议:
从PHP.net到file_exists:
This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.
此外:
file_exists
的结果将被缓存。
也许您必须致电clearstatcache()
修改强>:
您可以尝试以下操作:
<?php var_dump(file_exists("C:\\Windows\\System32\\java.exe"));
答案 2 :(得分:0)
遇到同样的问题并通过重新定位java.exe解决了这个问题 从Windows / System32文件夹到例如C:/ Java的 (假设可执行文件C:/Java/java.exe现在实际存在)&#39; file_exists(&#34; C:/Java/java.exe")&#39; (和&#39; is_executable(&#34; C:/Java/java.exe")&#39;) 现在应该回归真实。