【问题标题】:Popen doesn't work弹出不工作
【发布时间】:2015-10-18 05:00:59
【问题描述】:

似乎在我的服务器上popen() 根本不起作用。我通过浏览器访问test.php,文件postt1.phppostt2.php 没有被执行。 article1.txtarticle2.txt 文件未写入。所有文件都在同一个目录中。

可能是什么问题?

在文件test.php我有:

<?php
$pipe1 = popen('postt1.php', 'w');
$pipe2 = popen('postt2.php', 'w');

pclose($pipe1);
pclose($pipe2);
echo "end"; 
?>

内部文件postt1.php我有:

<?php
 $tosave =  "Hello there";

 $file = fopen("article1.txt","w");
 fwrite($file,$tosave);
 fclose($file);
 echo $tosave;
 echo "<br>done";
 ?>

postt2.php 中,除了写入文件article2.txt 之外,我有同样的事情。

【问题讨论】:

  • popen 需要一个命令作为第一个参数,你只是传递postt1.php,我会说类似php postt1.php。或者如果你想执行那些(postt1 & postt2)文件,请使用include
  • 您确定吗 - 此页面上的 popen 中没有其他参数 - stackoverflow.com/questions/70855/…

标签: php popen


【解决方案1】:

postt1.php end postt2.php 需要shebang tags (#!) 和执行权限。

通过告诉文件 PHP 解释器在文件的第一行(&lt;?php! 之前)的位置来添加 shebang 标记。最佳实践要求您应该通过env 命令访问解释器:

 #!/usr/bin/env php

<?php
 $tosave =  "Hello there";

 $file = fopen("article1.txt","w");
 fwrite($file,$tosave);
 fclose($file);
 echo $tosave;
 echo "<br>done";
 ?>

您也可以使用直接指向php 的shebang:#!/usr/bin/php。但这在整个系统中的便携性较差。


您还必须确保两个文件都具有可执行权限:

$ chmod +x posttl.php

【讨论】:

    猜你喜欢
    • 2021-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    相关资源
    最近更新 更多