比如要生成10000個或者更多個文件,如何提高速度?
這種webman寫估計不咋地,應(yīng)該不會快的,nodejs大概多少時間?
有一些地方有這種場景的,比如一些文章需要生成靜態(tài)html,文章可能幾十萬,這時候用php(tp或webman,不打算用swoole)就很慢,但發(fā)現(xiàn)用nodejs 快不止一點點
項目引入amphp 或者 reactphp 然后你就會發(fā)現(xiàn) js那一套怎么過來了 /手動狗頭
public function index()
{
$t1 = microtime(true);
$data = $this->testRange(10000);
foreach ($data as $file) {
fputs($file, "Hello World!");
fclose($file);
}
$t2 = microtime(true);
$tips = "運行時長:" . round(($t2 - $t1), 3) . 's';
var_dump($tips);
}
protected function testRange($len)
{
$public = public_path() . "";
for ($i = 1; $i <= $len; $i++) {
yield fopen($public . "test_" . $i . ".txt", "w");
}
}