0

A developer did a custom PHP script for me for importing posts into Wordpress from CSV file. The script worked fine on a staging site, which was on a different server, but when we moved it to my server, it can't download the CSV file and even if I manually import the file to the folder, it won't import it. It doesn't show any errors, just a blank page.

It's a shared hosting, so the provider has set the max_execution_time to 120, which will be enough for the script to run, but it times out on 30 seconds.

The script is using curl_setopt to get the file. The PHP version is 5.5

$userAgent = 'FreeRock.Eu/2.0 (http://www.freerock.eu/share.php)';
$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$address);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 400);
$html = curl_exec($ch);
if (!$html) {
echo "<br /> error number:" .curl_errno($ch);
echo "<br /> error:" . curl_error($ch);
exit;
}

return $html;
}

Then I have:

$z_html = fake_user_agent_http_get('https://www.myfilelocation.com');
$myfile = fopen("promotions.csv", "w") or die("Unable to open file!");
fwrite($myfile, $z_html);
fclose($myfile);

Would appreciate any help here.

Thanks Alexis

Alexis
  • 1
  • 1
  • Did you enable all errors? See: [How to get useful error messages in PHP?](http://stackoverflow.com/q/845021/660921) You probably don't have the `curl` extension installed or some such. – Martin Tournoij Jul 21 '16 at 10:59
  • All errors have been enabled in php.ini – Alexis Jul 21 '16 at 12:55

2 Answers2

0

There can be numerous reasons for this. Lets try a few things:

1) Add this in the top of the script so maybe you can see the error:

ini_set('display_errors',true);
error_reporting(e_all);

2) Try add the following in the top of the code to avoid the 30 seconds max execution time:

set_time_limit(0);

3) The hosting provider probably have php error logs available. Try to download them to figure out what the error is.

Patrik Grinsvall
  • 584
  • 1
  • 4
  • 22
  • Still nothing. max_execution_time is set to 120 in php.ini, but it still terminates at 30 sec. Here is the URL for the script: http://www.dealsoftomorrow.com/import/importer.php – Alexis Jul 21 '16 at 13:13
  • Just to be 100% sure, please add this in the top of the script: echo ini_get('max_execution_time');die(); – Patrik Grinsvall Jul 21 '16 at 14:10
0

Update - the timeout was caused by an nginx settings, but because it's a shared hosting, the 30 seconds timeout cannot be changed. The solution is to run the script via SSH.

Alexis
  • 1
  • 1