我有一个PHP脚本,根本不会为我加载。
当我尝试运行它时,它只是坐在那里,就好像它正在尝试加载页面一样,但什么都没发生。
它会创建指定的文件,但绝不会用任何数据填充它。
<?php
function time_elapsed_A($secs){
$bit = array(
'y' => $secs / 31556926 % 12,
'w' => $secs / 604800 % 52,
'd' => $secs / 86400 % 7,
'h' => $secs / 3600 % 24,
'm' => $secs / 60 % 60,
's' => $secs % 60
);
foreach($bit as $k => $v)
if($v > 0)$ret[] = $v . $k;
return join(' ', $ret);
}
$pass = $_POST['$pass'];
// change this to current sessionId
$sessionId = $_POST['sessionId'];
echo $sessionId;
//$apiKey = 'AIzaSyALTBvIbopERsN6zldPA7zwCAmx7dxUSII';
$baseData = 'user_id=2239430076&user_name=GenBrannigan&common_data={"isJailbroken":0,"android_id":"-1","device_type_name":"QMV7B 4.2.2","user_id":2239430076,"sdk_ver":"0092","terrace_type":"google","device_detail_type":"QMV7B","advertising_id":"4f680189-4b8e-404b-8887-293252ef71cd","mac":"-1","s_mac":"-1","device_uid":"4f680189-4b8e-404b-8887-293252ef71cd","idfa":"-1","device_date":"Wed Nov 19 23:25:57 2014","app_type_name":"app","adId":"4f680189-4b8e-404b-8887-293252ef71cd","server_id":76,"s_adid":"-1","isPirated":0,"vendorId":"-1","user_name":"GenBrannigan","SAID":"4f680189-4b8e-404b-8887-293252ef71cd","sh1dId":"-1","md5dId":"-1","pkg_version":"1.7.0","apns_token":"-1","nsuuId":"-1", "device_os_version":"4.2.2"}&ex_data=';
$startTime = time();
echo $startTime;
$csv = fopen("mappedGalaxies.csv", "w");
fwrite($csv, "Planet, System, Galaxy, Username, Score, Debris (M), Debris (C), Alliance, Time\n");
for ($galaxy = 1; $galaxy < 21; $galaxy++) {
for ($system = 1; $system < 601; $system++) {
$ex_data = '{"planet_id":-1,"sid":'.$system.',"language":"en","gid":'.$galaxy.'}';
$sign = md5($sessionId . $ex_data);
$finalData = $baseData . $ex_data . "&type=1";
$url = "http://54.193.106.113/ING004/android1/WebServer/Web/sogame/newControl/nmUniverse/getUniverse?sign=".strtoupper($sign);
$connection = curl_init($url);
curl_setopt($connection, CURLOPT_POSTFIELDS, $finalData);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($connection, CURLOPT_ENCODING, "gzip");
$result = curl_exec($connection);
$err = curl_error($connection);
$baseObj = json_decode($result, true);
curl_close($connection);
for ($planet = 1; $planet < 16; $planet++) {
$planetData = $baseObj["planets"][$planet];
if (isset($planetData["user_name"])) {
if ($planetData["score"] > $_POST ['minScore']) {
// write out the information
$gala = $planetData["position"][0];
$sys = $planetData["position"][1];
$user = $planetData["user_name"];
$alliance = $planetData["all_name"];
$score = $planetData["score"];
$debris = $planetData["runins"];
$timeOfFind = new DateTime('now');
$burrista = $planet . "," . $sys . "," . $gala . "," . $user . "," . $score . ",". $debris[0] . ",". $debris[1]."," . $alliance . "," . $timeOfFind->format('m-d H:i:s') . "\n";
fwrite($csv, $burrista);
#echo "Found: " . $burrista;
}
}
}
}
}
$endTime = time();
echo "Finished: " . time_elapsed_A($endTime-$startTime) . "\n";
?>
我只是不明白。它在我的本地主机上工作过一次,我无法让它再次运行。
好的,这是我的'特定'问题:为什么页面只加载一次而没有做它应该做的事情,即获得一个http共鸣并填充所提到的csv文件。
特定的所需操作:我希望我的脚本每次都加载并使用检索到的http数据填充csv文件。
这对你来说是否足够具体?
答案 0 :(得分:1)
尝试使用file_put_contents()
代替fopen()
和fwrite()
,除非您需要对文件进行高级控制。