Home >Backend Development >PHP Tutorial >How to write millions of test data in PHP at one time
This article mainly shares with you the method of writing millions of test data at a time in PHP. It is effective in personal testing. I found it through various online searches and the execution efficiency is even higher than through navicat. Hope it helps everyone.
Post the core code for your reference.
1. PHP code
//添加测试数据 private function add_test_data($max=1000000){ $model=M('Blog'); //$max=1000000; //测试数 $data=array(); $test=array(2,3,6,7); for($i=0;$i<$max;$i++){ $key=rand(0,3); $data['blog_category_id']=$test[$key]; $data['blog_title']='New博客'.($i+$max+1); $data['blog_thumb']='/data/upload/images/blog_thumb/5aa1dda49e9d3_small.jpg'; $data['blog_content']='施蒂利克接口是否就付费圣诞节快乐代付即可劳动非顶级分类分手的距离时代峰峻开始的放假快乐番薯的房价克里斯多夫监考老师的房价'; $data['blog_explain']='是的冯绍峰的冯绍峰的'; $data['blog_addtime']=time(); $result=$model->add($data); if($result===false){ return false; } } return true; }
2. Modify the configuration file. My local environment is win7x64+phpstudy2017+php7.0.12-nts+nginx
php.ini max_execution_time = 10000 memory_limit = 2048M nginx.conf fastcgi_connect_timeout 10000; fastcgi_send_timeout 10000; fastcgi_read_timeout 10000; my.ini innodb_flush_log_at_trx_commit=2 innodb_log_buffer_size=16M innodb_buffer_pool_size=2000M innodb_log_file_size=512M innodb_thread_concurrency=0
3. There are pictures and there are truths (PS: Ignore why it is 3.6 million, the screenshot of that time was taken when I inserted millions of test data)
Related recommendations:
How to quickly insert millions of test data in php+mysql (12s)
The above is the detailed content of How to write millions of test data in PHP at one time. For more information, please follow other related articles on the PHP Chinese website!