Php 如何删除pctnl_fork()添加的头文件?
我使用pctnl_fork将一个大任务分解为多个进程,它工作得很好,只是有一件令人讨厌的事情:出于某种原因,输出中嵌入了内容类型:text/html,而我所做的一切似乎都无法摆脱它 以下是该问题的一个工作示例:Php 如何删除pctnl_fork()添加的头文件?,php,http-headers,Php,Http Headers,我使用pctnl_fork将一个大任务分解为多个进程,它工作得很好,只是有一件令人讨厌的事情:出于某种原因,输出中嵌入了内容类型:text/html,而我所做的一切似乎都无法摆脱它 以下是该问题的一个工作示例: <?php ob_start(); $pid = pcntl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { // we are the parent
<?php
ob_start();
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
pcntl_wait($status); //Protect against Zombie children
} else {
$fh=fopen('/var/www/html/test.txt','w');fwrite($fh, time());fclose($fh);
exit(0);
}
header_remove();
ob_end_clean();
echo " done";
?>
使用header_remote,它可以去掉X-Powered-By头,但内容类型头仍然保留:
Content-type: text/html done
我把头发拔了出来,想把它修好,但没有用。我想ob_end_clean肯定能解决这个问题,但事实并非如此。如果有人有任何建议,我将永远感激。不要在web服务器环境(如mod_php)中使用pcntl_fork。正如您所观察到的,它在web服务器中运行时无法正常工作,因此在较新版本的PHP中,它在CLI SAPI之外不可用
Content-type: text/html done