While i am using php code to get all the records from the mysql table having nearly 10,000 records,it is executing slowly.
Can any one tell me how to get the records with the minimum execution time
While i am using php code to get all the records from the mysql table having nearly 10,000 records,it is executing slowly.
Can any one tell me how to get the records with the minimum execution time
1 for perticular script
set_time_limit(number in seconds);
2 in php.ini in entire php( for all script)
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
3 where php.ini is not accessible(like on shared server) write it into .htaccess file
<IfModule mod_php5.c>
php_value max_execution_time 259200
Ther first thing you should do is to ANALYZE
you query and see what is the reason of such low speed.
1) If your select does not use INDEX - you definitely should create index (if it is not present) or force your query to use that index manually (FORCE INDEX(primary)
etc.).
2) If you query created temporary table (Using temporary
in your explain output) - you need to increase allocated memory for you MySQL server, so that it can create temporary table in memory and not write it to HDD (that takes looooooot of time). For this optimization check tmp_table_size
and max_heap_table_size
in mysql config.
3) And only in case you have no problems I described above and you just have some complicated logic in you script that processes your data, you can set_time_limit(0)
(means unlimited) directly from you php code, or edit php.ini and set max_executeion_time
to some higher value. Or, as an alternative, you can install opcache or other opcode cacthing system that can a little bit increase the speed of your code (2-10 times usually).
(The problem may be not only in your server, but in your connection speed and amount of data that should be downloaded - maybe, select is fast, but data load time is long, so check the size of response with Firebug and compare with you bandwidth)
We need to see the DB structure and your query to give a better answer.
However, below will simply provide your script more time to run the query.
You can do this in two ways.
set_time_limit(number in seconds);
max_execution_time = 3000
to a higher value.Option 1 will increase the execution time only for that script. Option 2 will increase execution time in all scripts.
Try to add an index. But if you want all the records, with this lot, it's normal that it takes time.
Try to increase allowed memory.
<?php ini_set('memory_limit','512M'); ?>
For the execution time, take a look to :