Home >Backend Development >PHP Tutorial >How to write millions of test data in PHP at one time

How to write millions of test data in PHP at one time

小云云
小云云Original
2018-03-19 13:08:041958browse

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[&#39;blog_category_id&#39;]=$test[$key];
            $data[&#39;blog_title&#39;]=&#39;New博客&#39;.($i+$max+1);
            $data[&#39;blog_thumb&#39;]=&#39;/data/upload/images/blog_thumb/5aa1dda49e9d3_small.jpg&#39;;
            $data[&#39;blog_content&#39;]=&#39;施蒂利克接口是否就付费圣诞节快乐代付即可劳动非顶级分类分手的距离时代峰峻开始的放假快乐番薯的房价克里斯多夫监考老师的房价&#39;;
            $data[&#39;blog_explain&#39;]=&#39;是的冯绍峰的冯绍峰的&#39;;
            $data[&#39;blog_addtime&#39;]=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. How to write millions of test data in PHP at one timeThere 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn