Hi friends, with a lot of thelp from this forum's users and reading, I made a script to read a ascii/text file and find/show the records (lines) with the given search pattern. The script works fine, but ... it's slow!
Thanks in advance,
Jean H//
This is my script:
define('archivo', 'http://www ... myfile.dat');
$archivo = fopen (archivo,'r');
$comodin=0;
while (!feof($archivo))
{
$buffer = fgets($archivo, 4096);
# Quitamos los espacios en el valor ingresado
# $serial = trim($serial);
# Fill with 0s at beginning
$serial = str_pad($serial, 7, "0", STR_PAD_LEFT);
# UHMM, no recuerdo si debemos quitar los puntos o comas
# Quitamos los puntos "."
# $serial = str_replace(".", "", $serial);
# Quitamos las comas ","
# $serial = str_replace(",", "", $serial);
# Let's see where the comma is
$pos_coma = strpos($buffer, ",");
$largo_cadena = strlen($buffer);
$largo_premio = $largo_cadena - $pos_coma;
$buffer_aux = substr($buffer, $pos_coma+1, $largo_premio);
$existe = stristr($buffer, $serial);
if ($existe === false )
{
echo " ";
}
else
{
echo '<p><font color="blue" face="Arial">Found!! <BR>';
echo "$buffer_aux <BR> </font></p>";
$comodin = $comodin + 1;
}
}
if ( $comodin == 0 )
{
echo '<p><font face="Arial" color="red">Not found </font></p>';
}
fclose ($archivo);
PHP Speed, can I improve?
Moderator: General Moderators
You seem to be opening files from the internet, if you are doing this on a local machine and you have a slow internet connection (dial-up?) this would be a factor.
How big is the file you are opening ? How is the data formatted in the file ?
As "releasedj" said, it could be the server performance, what's the spec ? What else is running on the "server" ?
Regards,
How big is the file you are opening ? How is the data formatted in the file ?
As "releasedj" said, it could be the server performance, what's the spec ? What else is running on the "server" ?
Regards,
- Heavy
- Forum Contributor
- Posts: 478
- Joined: Sun Sep 22, 2002 7:36 am
- Location: Viksjöfors, Hälsingland, Sweden
- Contact:
Or are you maybe doing something that a database engine does better?
If you are in total control of the content of that file, and use it only for this application of yours, you could consider using a database instead of using PHP to select ranges out of the file.
One more thing. I only understand comments written in swedish and english...
This thread teached me a lot: viewtopic.php?t=8869
If you are in total control of the content of that file, and use it only for this application of yours, you could consider using a database instead of using PHP to select ranges out of the file.
One more thing. I only understand comments written in swedish and english...
This thread teached me a lot: viewtopic.php?t=8869