Test results: There was an error opening the file during the test, and the data that was written after the execution of the program was incomplete, only 999997 lines and 3 rows were missed. The most important point is that the time spent more than 307 seconds, and the use of fwrite only spent 10 seconds more time, the gap is not small.
d:\myphp\research>php test2.php PHP warning:file_put_contents (Ratings.txt): Failed to open stream:permission Denied in D:\myphp\research\test2.php on line 79
Warning:file_put_contents (Ratings.txt): Failed to open stream:permission Denie D in D:\myphp\research\test2.php on line 79 Spend time: |307.0586669445|second (s)
Test results: Write 1 million lines of records, about 10 seconds to write, for PHP, the speed is good. This was tested on my personal computer, and if tested on a production machine, it might be faster. d:\myphp\research>php test2.php Spend time: |10.764221191406|second (s)
The data written with Fwrite is complete. 999997,qovczyfjflfhjigygxac615koxdx3yii,246982,0.03 999998,qovczyfjflfhjigygxac615koxdx3yii,240160,0.39 999999,qovczyfjflfhjigygxac615koxdx3yii,46296,0.61 1000000,qovczyfjflfhjigygxac615koxdx3yii,26211,0.14
3. Summary If you want to write a large amount of data into the file, it is recommended to use fwrite, do not use file_put_contents. It is also recommended to use fwrite in high-concurrency requests.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.