php file_put_contents耗时2秒且未阻止

时间:2017-06-13 14:52:45

标签: php sed file-get-contents file-put-contents

我正在做一个config.inc文件

<?php echo 'old value';

我使用preg_replace和file_put_content进行编辑:

include("config.inc");//this shows me the old value
$txt = file_get_contents("config.inc");//but this show the new value

if ($_GET['val']) {
    file_put_contents("config.inc", "<?php echo '".$_GET['val']."';");
    //echo "content now is".file_get_contents("config.inc");
    //hey ! i changed your value says file_get_content()

    //sleep(5);//this currently solve the issue, but that's not a solution
    header('Location: /adminprivate/testing.php');
    exit();
}
else {
    echo htmlspecialchars($txt);
    echo "
    <form method='get'>
        <input type='text' name='val' />
        <button type='submit'>Change value</button>
    </form>";
}

我的问题是我的include()在file_put_content()调用后大约两秒钟回显旧值,但在我的页面重新加载时没有阻塞。

现在,即使我使用exec('sed -i ...'),php似乎也不会等待文件写入,只是过早重新加载。

问题不在于标题,好像我在2秒内手动重新加载,旧值就在那里。

我想知道为什么file_get_content可以在包含查找旧内容时找到正确的内容,以及如何防止我的页面重新加载,除非我100%确定我的包含可以使用

0 个答案:

没有答案