0

I've noticed that the directory on which one of the PHP script is installed have very large error_log file almost of 1GB size, mostly the errors are generated by coding on line 478 and 479.. example of the error from error_log file is below:

PHP Warning:  filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 478
PHP Warning:  filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for /home/khan/public_html/folder/ZBall.jar in /home/khan/public_html/folder/index.php on line 479

I have the following coding, line 477 to 484

foreach ($mp3s as $gftkey => $gftrow) {
   $ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
   $ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
 }
 array_multisort($ftimes2,SORT_DESC,$ftimes);
 foreach ($ftimes as $readd) {
   $newmp3s[] = $readd[1];
 }

Please help me on this.

Thanks.. :)

3 Answers 3

2

The stat failed error would indicate that the file /home/khan/public_html/games/ZBall.jar either doesn't exist, or can't be read due to a permission error. Make sure the file exists in the place PHP is looking, as that seems like the most like cause of the problem.

Since it comes from the array $mp3s, make sure that array contains names of files that exist and modify it if not.

Sign up to request clarification or add additional context in comments.

5 Comments

well the file does exist and also the file gets downloaded, there is no issue at front-end.. problem is error_log file is generated and as the files are downloaded in large number the file size gets bigger and bigger.. have applied @Gabriel Sosa edited code.. hope it would work.. :-)
After applying @Gabriel Sosa's the following error is generated... <br/>PHP Warning: array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Argument #1 is expected to be an array or a sort flag in /home/khan/public_html/folder/index.php on line 483 PHP Warning: Invalid argument supplied for foreach() in /home/khan/public_html/folder/index.php on line 484 <br/> Code from line 483-486 <br/> array_multisort($ftimes2,SORT_DESC,$ftimes); foreach ($ftimes as $readd) { $newmp3s[] = $readd[1]; } <br /> Any kind of help would be appreciated.. Thanks..
@HaroonKhattak Your problem is not that you have a growing error log, it is that your code is producing errors. Something is preventing Apache/PHP from being able to stat that file.
@HaroonKhattak That new error looks to be because the array $ftimes2 is not created. If file_exists() returns false, as it will when that file isn't found (per the stat error), your array will never be built, and will error when passed to array_multisort()
well i've added absolute path as read on forum that filemtime on some systems doesn't work unless you specify the absolute path instead of the relative path.. lets see.. foreach ($mp3s as $gftkey => $gftrow) { if (file_exists($thecurrentdir.$gftrow)) { $ftimes[$gftkey] = array(filemtime('/home/khan/public_html/folder/' . $thecurrentdir.$gftrow),$gftrow); $ftimes2[$gftkey] = array(filemtime('/home/khan/public_html/folder/' . $thecurrentdir.$gftrow),$gftrow); } } array_multisort($ftimes2,SORT_DESC,$ftimes); foreach ($ftimes as $readd) { $newmp3s[] = $readd[1]; }
1

ask for the file before doing something with it. checm my edit:

<?php
foreach ($mp3s as $gftkey => $gftrow) {
   if (file_exists($thecurrentdir.$gftrow)) {
     $ftimes[$gftkey] = array(filemtime($thecurrentdir.$gftrow),$gftrow);
     $ftimes2[$gftkey] = filemtime($thecurrentdir.$gftrow);
   }
 }
 array_multisort($ftimes2,SORT_DESC,$ftimes);
 foreach ($ftimes as $readd) {
   $newmp3s[] = $readd[1];
 }

3 Comments

i've added your edited code, site is working.. so far no error_log file is created in that folder.. will let u know if any error is generated.. Thanks.. :-)
Now this error is generated... PHP Warning: array_multisort() [<a href='function.array-multisort'>function.array-multisort</a>]: Argument #1 is expected to be an array or a sort flag in /home/khan/public_html/folder/index.php on line 483 PHP Warning: Invalid argument supplied for foreach() in /home/khan/public_html/folder/index.php on line 484 Code from line 483-486 array_multisort($ftimes2,SORT_DESC,$ftimes); foreach ($ftimes as $readd) { $newmp3s[] = $readd[1]; }
if the foreach is throwing that, looks like none of your files exists, so the last foreach is trying to iterate over a non-existent array. check the path of the files, and if you like accept the answer :)
0

There is a function on PHP.net site which removes a bug on Windows about filemtime

function GetCorrectMTime($filePath) { 

$time = filemtime($filePath); 

$isDST = (date('I', $time) == 1); 
$systemDST = (date('I') == 1); 

$adjustment = 0; 

if($isDST == false && $systemDST == true) 
    $adjustment = 3600; 

else if($isDST == true && $systemDST == false) 
    $adjustment = -3600; 

else 
    $adjustment = 0; 

return ($time + $adjustment); 
}

source: http://php.net/manual/tr/function.filemtime.php#100692

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.