我有一个类似这样的代码:
$file = fopen( "debug.txt", "w" );
$command = "myExe.exe param0 param1";
fprintf( $file, "starting\r\n" );
fflush( $file );
system( $command );
fprintf( $file, "the end...\r\n" );
fflush( $file );
它打印“开始”而不是“结束......”。 system() 函数挂起。
myExe.exe 是一个用C++ 编写的应用程序,它实际上终止了;即 myExe 的主要功能以这样的代码结束:
FILE* f = fopen( "test.txt", "w" );
fclose(f);
return 0;
test.txt 被创建,这意味着“myExe.exe”正常工作并完成。
每次调用php文件都不会出现这个问题;有时挂起,有时工作...
任何帮助和想法都将被应用。提前致谢。
信息;
操作系统:win xp
php 服务器:wamp 服务器 2.0
编辑:我的问题与我的调试文件无关。它是关于 system() 或 exec() 函数的。我可以删除所有其他行。
我的 php 脚本在大约 4/5 次尝试中运行良好。在 system() 调用后,我调用了一些 sql 函数,但是当 system() 挂起时,我的页面会出现致命错误。
最佳答案
Windows ( http://bugs.php.net/bug.php?id=44942 ) 上的 php 中存在一个已知错误。
您可能想尝试一种解决方法,在调用 exec 函数之前关闭 session (调用 session_write_close() )。
关于即使 system() 中的命令完成,PHP system() 也会挂起,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4555833/