简体   繁体   English

如何在浏览器中同时运行两个php脚本,并在同一文件中运行fwrite()

[英]How to run two php scripts at the same time in browser and fwrite() in the same file

I have to crash the script. 我必须崩溃脚本。 I have a class with a method that opens and writes in the file. 我有一个带有打开和写入文件的方法的类。 I have 2 more files that are the same for calling this method. 我还有2个相同的文件用于调用此方法。

I have tried for() loop and sleep() 我已经尝试过for()循环和sleep()

//Method
    public function write($filename, $text, $sleep)
    {
        $filename .= '.txt';
        $fh = fopen($filename, 'w');
        flock($fh, LOCK_EX);
        $write = fwrite($fh, $text);
        if ($sleep != 0) {
            sleep($sleep);
        }
        fclose($fh);
        return $write;
    }


//firstFile.php

$rw = new RW();

$start = microtime(true);

$rw->write('fileeeeeeee', 'FDSABNIFGA', 0);

echo $time = microtime(true) - $start;


//secondFile.php

$rw = new RW();

$start = microtime(true);

    $rw->write('fileeeeeeee', 'HEHEEH', 0);

echo $time = microtime(true) - $start;

I need to run firstFile.php and secondFile.php at exactly the same time in the browser. 我需要在浏览器中完全同时运行firstFile.php和secondFile.php。

If you want to deliberately crash a script you could just setup an infinite loop. 如果要故意使脚本崩溃,可以设置一个无限循环。

for($i = 1; $i != 0; $i++) {
    echo $i . '<br />';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM