iam coding a SEMrush.com php API so the problem is that i should walk through uploaded file contain at least 3000 website for the traffic the information needed is like that photo so i just need the organic search the problem is that the search stops before it complete the 3000 websites like in that first photo
and thats my code
<?php
set_time_limit(0);
$database = "au";
$key = "api key";
$fname = "results-3.csv";
function getValues($domain,$date='') {
global $database,$key;
$keywords = $traffic = 0;
$url = "http://api.semrush.com/?type=domain_ranks&key=$key&display_date={$date}&database={$database}&export_columns=Ot&domain=$domain";
$reply = trim(@file_get_contents($url));
// "ERROR 50 :: NOTHING FOUND"
if (strpos($reply,'ERROR ')===0) {
return $reply;
}
elseif(preg_match('#Organic Traffic\s*(\d+)#s',$reply,$m)) {
return array($m[1]);
}
}
?><!DOCTYPE html>
<html>
<head>
<style type="text/css">
p {
color: darkslategray;
margin: 0;
}
p.error {
color: darkgray;
}
h3 {
color: black;
margin: 1em 0 0.4em 0;
}
</style>
</head>
<body>
<?php
// got file
if(@$_FILES["infile"]["size"] AND @$_POST['date']) {
$tFile=tempnam("/tmp","dom");
if(!move_uploaded_file($_FILES["infile"]["tmp_name"],$tFile))
die("Can not move upload file");
$domains=array_filter(array_map("trim",file($tFile)));
$date= date("Ym",strtotime($_POST['date']))."15.";
$csvF=fopen($fname,"wb+");
if(!$csvF)
die("Can not open $fname");
fwrite($csvF, "Domain,$_POST[date] Seo Traffic\n");
foreach($domains as $domain) {
echo "<h3>$domain</h3>";
//$today = getValues($domain);
$reply = getValues($domain,$date);
if (is_array($reply)) {
$domainTraffic = $reply[0];
echo '<p>Ok: ' . $domainTraffic . '</p>';
} else {
$domainTraffic = '';
echo "<p class=\"error\">{$reply}</p>";
}
fwrite($csvF, "$domain,$domainTraffic\n");
flush();
}
fclose($csvF);
echo "<h1><a href=$fname target=_blank>Download file</a></h1>";
} else {
?>
<div style="text-align:left;margin-left:20%">
<form method="post" enctype="multipart/form-data">
SE Traffic for Date entered by user
<hr>
Report Date:<input type=text size=12 name=date value="<?php echo date("Y-m-15",strtotime("-10 months"))?>"> (required!)<br>
File (txt or csv, one domain per line):<input type=file name=infile><br><br>
<input type=submit value="Start">
</form>
</div>
<?php
}
?>
</body>
</html>