Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php文件内容需要2秒,并且没有阻塞_Php_Sed_File Get Contents_File Put Contents - Fatal编程技术网

php文件内容需要2秒,并且没有阻塞

php文件内容需要2秒,并且没有阻塞,php,sed,file-get-contents,file-put-contents,Php,Sed,File Get Contents,File Put Contents,我目前正在做一个config.inc文件 <?php echo 'old value'; 这看起来不是一个好主意。你想用这个做什么?为什么不直接将变量内容写入文件,然后改为echo file\u get\u contents?这会更改我的config.inc文件,其中包含变量声明,而不是echos;)这听起来像是个糟糕的策略。您可以将配置参数存储在JSON文件中,并改为读/写该文件。动态修改代码不是一个好主意。你也在运行opcache吗?把一个值放在一个文件中,以后再重写是一个坏主意,试

我目前正在做一个config.inc文件

<?php echo 'old value';

这看起来不是一个好主意。你想用这个做什么?为什么不直接将变量内容写入文件,然后改为
echo file\u get\u contents
?这会更改我的config.inc文件,其中包含变量声明,而不是echos;)这听起来像是个糟糕的策略。您可以将配置参数存储在JSON文件中,并改为读/写该文件。动态修改代码不是一个好主意。你也在运行opcache吗?把一个值放在一个文件中,以后再重写是一个坏主意,试着用一个db它会更容易,而且更快。实际上,我不能只用db来实现这一点,你可以把它看作是一个非序列化、序列化的文件,但它实际上是通过一个include实现的,它执行了大量的测试,并且是手工修改的。我知道这不是最好的方法,但这就是我被赋予的工作
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>";
}