0

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

lalith458
  • 695
  • 2
  • 12
  • 30

4 Answers4

3

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

alok.kumar
  • 380
  • 3
  • 11
1

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)

kovpack
  • 4,905
  • 8
  • 38
  • 55
0

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.

  1. At the start of your php file add the code set_time_limit(number in seconds);
  2. You can edit your php.ini files 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.

Ela Buwa
  • 1,652
  • 3
  • 22
  • 43
  • If it is slow, try optimizing the database query first - or the database. Allowing to wait longer isn't really the option you should go for... – Sven Nov 13 '13 at 07:39
0

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 :

Increase max execution time for php

Community
  • 1
  • 1
David Ansermot
  • 6,052
  • 8
  • 47
  • 82