2

The following script works fine on browser. But in cron job it gives an error.

fgetcsv expect parameter 1 to be resource,boolean given

Please help.

Code:

$handle = fopen("http://www.spc.noaa.gov/climo/reports/today_hail.csv", "r");

while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    $import="INSERT into mytable Values('" . mysql_real_escape_string($data[0]) . "','$data[1]','" . mysql_real_escape_string($data[2]) . "','" . mysql_real_escape_string($data[3]) . "','" . mysql_real_escape_string($data[4]) . "','$data[5]','$data[6]','" . mysql_real_escape_string($data[7]) . "')";

    mysql_query($import) or die(mysql_error());        
}
fclose($handle); 
Dexpras
  • 426
  • 4
  • 11

1 Answers1

2

It will be your permissions.

Ensure that your permissions & file ownership are configured correctly, being able to run from the browser but not from cron almost always indicates a permission problem.

Ryan
  • 3,552
  • 1
  • 22
  • 39
  • More specifically, cron runs under a different user than your webserver (and PHP implicitly) does. This other user does not have correct permissions for whatever file you are trying to read from. – Sergiu Paraschiv Feb 24 '14 at 09:56
  • It says "expect parameter 1 to be resource, boolean ***given***". As in "please provide me with a file handle resource, _not_ a boolean". – Sergiu Paraschiv Feb 24 '14 at 10:01
  • @SergiuParaschiv Thank you sir, So do you still think that the problem is with permissions.. – Dexpras Feb 24 '14 at 10:07
  • @user3206125 the boolean is most likely false, due to it not being able to fetch the resource. – Ryan Feb 24 '14 at 10:09