使用php向mysql发送2300请求需要2小时,如何优化

使用php向mysql发送2300请求需要2小时,如何优化,php,mysql,rss,Php,Mysql,Rss,我在做一个报纸项目,但是没有Rss提要,所以我不得不用php编程制作它的提要,所以我有2300个处理页面的过程,并在Mysql中插入处理结果 所以我使用的技术是处理每一个页面,然后在mysql中插入它的内容,它工作得很好,但有时我让mysql服务器消失了 我试图处理30页,并在一个请求中插入它们,但过了一段时间它就停止了 所以我想问的是,有没有什么方法可以优化这个处理过程,以减少所用的时间 非常感谢您的批量插入方法是正确的,可能会有所帮助。你需要找出为什么它会像你说的那样在一段时间后停止 很可能

我在做一个报纸项目,但是没有Rss提要,所以我不得不用php编程制作它的提要,所以我有2300个处理页面的过程,并在Mysql中插入处理结果

所以我使用的技术是处理每一个页面,然后在mysql中插入它的内容,它工作得很好,但有时我让mysql服务器消失了

我试图处理30页,并在一个请求中插入它们,但过了一段时间它就停止了

所以我想问的是,有没有什么方法可以优化这个处理过程,以减少所用的时间


非常感谢您的批量插入方法是正确的,可能会有所帮助。你需要找出为什么它会像你说的那样在一段时间后停止

很可能是php脚本超时了。在php.ini文件中查找以确保其足够高以允许脚本完成

另外,确保您的mysql配置允许一个新的批处理,因为您发送的批处理可能很大


希望有帮助

MySQL服务器消失的原因有很多

不管怎样,很奇怪,你加载了整个页面。通常RSS提要意味着您只在其中放置一个主题和一些文本片段。我将RSS提要创建为简单的XML文件,这样就不必在每次点击时都从MySQL加载数据。创建新闻->重新生成RSS XML文件,撰写新文章->重新生成RSS XML文件

如果仍要准备要插入的数据,只需创建一个包含所有插入内容的文件,然后从此文件加载数据

$ mysql -u root
mysql> \. /tmp/data_to_load.sql
对!!每次2300人

$generated_sql = 'insert into Table (c1,c1,c3) values (data1,data2,data3);insert into Table (c1,c1,c3) values (data4,data5,data6);';

$sql_file = '/tmp/somefile';
$fp = fopen($sql_file, 'w');
fwrite($fp, $generated_sql, strlen($generated_sql)); // wrote sql script
fclose($fp);

`mysql -u $mysql_username --password=$mysql_password < $sql_file`;
在最后一行中必须使用反勾号

$ mysql -u root test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A    

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 171                          
Server version: 5.1.37-1ubuntu5.5 (Ubuntu)               

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> create table test (id int(11) unsigned not null primary key);
Query OK, 0 rows affected (0.12 sec)                                

mysql> exit
Bye        

$ echo 'insert into test.test values (1); insert into test.test values (2);' > file
$ php -a
Interactive shell

php > `mysql -u root < /home/nemoden/file`;
php > exit

$ mysql -u root test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 180
Server version: 5.1.37-1ubuntu5.5 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from test
    -> ;
+----+
| id |
+----+
|  1 |
|  2 |
+----+
2 rows in set (0.00 sec)

因此,正如您所看到的,它工作得非常完美。

需要检查的其他内容是max connections。感谢您的回答,max_execution_time:30在php.ini中,我没有权限修改它,我正在使用我的脚本集_time_limit10000,但是,如果我处理并插入每一个页面,那么这个过程将持续两个小时,如果我尝试了30个页面,那么它将停止。你可以做的是修改你的php脚本,这样它就不用直接调用mysql,而是将所有sql语句写入一个文件。一旦文件准备好,您就可以从命令行mysql-uuser-ppabrow DATABASE\u NAME\/tmp/data\u to\u load.sqlIt'是一个mysql shell。如果您在Windows上,您可以使用phpMyAdmin、Mysql工作台、EMS SQL管理器等\/path/to/sql/file是一个sql查询。就像选择。。。或者插入…我的过程可以是每6-3小时一次,所以它必须是自动化的,这种方式可以自动化吗?!