tags:

views:

12

answers:

1

Hey guys. I'm running a script that looks for a specific term in a pdf file. Well, actually I'm reading the pdf file as a txt file and look for the term there. The script processes over 20k files. But, unexpectedly, the script breaks after it hits a file that is over 50mb long. It stops.

What could the reason be? Here's an excerpt of the script:

// Proceed if file exists
if(file_exists($sourcePath)){
    echo "file exists\n";
    if(filesize($sourcePath) > 0){
        echo "filesize is greater than 0\n";
        $pdfFile = fopen($sourcePath,"rb");
        $data = fread($pdfFile, filesize($sourcePath));
        fclose($pdfFile);

        // Search for string
        if(stripos($data,$searchFor)){
            echo "Success. encrypt found\r\n";
            fwrite($errorFileHandler,"Success. encrypt found\r\n");
        }else{
        .....
        }
      ...
      ...

What could be the problem?

A: 

Hey guys, I figured it out. There was not enough memory set for PHP. In the error log there is a fatal error that the script ran out of memory.

Kel
A cleaner way would be to search the file in smaller blocks - there will always be a file larger than available memory.
Piskvor