On Tue, Nov 24, 2009 at 08:40:09AM -0500, Rahul S. Johari wrote: > Ave, > > I'm connecting to a foxpro database (dbase) and simply running a > search to retrieve a record. It's a very simple code. > The problem is, as the database is growing, the search is becoming > ridiculously slow ... and I mean it's taking "minutes". When the dbase > had 10,000 records ... search was fast & efficient ... as if you were > connecting to a mySQL Database. Now that the database has over 75,000 > records and still growing ... it's taking minutes to search. > > The database has about 35 fields; Search is based on a phone number. > This is the code ... > > <?php > #Open DBF > $db = dbase_open("dbase.dbf", 0); > > #PULL UP RECORD > if ($db) { > $record_numbers = dbase_numrecords($db); > for ($i = 1; $i <= $record_numbers; $i++) { > $row = dbase_get_record_with_names($db, $i); > if ($row['PHONE'] == $_POST['PHONE']) { > > #Retrieve row & display fields > echo $row['STUFF']; > } > } > } > ?> > > It works ... but it's getting way too slow. > > One thing with FoxPro DBF's is that they use an Index file for > searches within FoxPro. These are .CDX files which contain the Index. > You can create an Index on, for example, PHONE field. However I don't > think there's any way in PHP to reference this Index file for faster > searches. > > Is there any possibility to improve search response time? > Check the PHP routines you use to access your xBase files. If none of them mention indexes, I think you'll find that the PHP xBase drivers do not *use* them. One problem is that dBase uses .ndx indexes, FoxPro uses .cdx indexes, and others use .ntx files. xBase drivers are written for the file format itself, not for the multiple kinds of indexes. Moreover, without selecting the specific index tag, your search won't go any faster as a result of the index. I suspect the bottleneck is in the way the drivers access the file. xBase is a fixed length record format with a variable length header, so it's pretty simple and fast to pull up successive records. I wrote a C program many years ago to access xBase files: http://sourceforge.net/projects/dbfsak Unfortunately, it's not possible with this program to access individual fields by name. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php