<?php
$dbhost = 'xx';
$dbuser = 'xx';
$dbpass = 'xxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('url') or trigger_error("Unable to switch to the database: " . mysql_error());
function arr($num){
$ch = curl_init();
$r= rand (1,90);
$url="https://www.googleapis.com/customsearch/v1?q=Gravity%20Falls%20Latest%20images&num=10&start=".$r."&safe=off&cx=x:2hdsc4__avm&filter=0&c2coff=disable&alt=json&key=x";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
$a=intval($num);
$data = json_decode($output, true);
$se= $data['items'][$a]['pagemap']['cse_image'][0]['src'];
$query = mysql_query("SELECT `url` FROM `url` WHERE `url`='".$se."'");
if (mysql_num_rows($query) != 0)
{
$rr= rand (1,10);
arr($rr);
}else{
mysql_query("INSERT INTO `url`(`url`) VALUES ('".$se."')");
return $se;
}
}
$rr= rand (1,10);
echo arr($rr);
require_once("src/facebook.php");
$config = array();
$config['appId'] = 'x';
$config['secret'] = 'x';
$config['fileUpload'] = true;
$fb = new Facebook($config);
$params = array(
"access_token" => "xxx",
"message" => "",
"url" => "".arr($rr)."",
);
try {
$ret=$fb->api('/1111/photos', 'POST', $params);
echo 'Photo successfully uploaded to Facebook Album';
}
catch(Exception $e) {
echo $e->getMessage();
}
mysql_close($conn);
?>
我在5到6台服务器上尝试了这个,所有人都给了我500 error
,但当我删除sql连接时,它可以工作!我提供了所有正确的mysql信息。
那为什么它显示500?
修改
如果我发表评论
$query = mysql_query("SELECT `url` FROM `url` WHERE `url`='".$se."'");
if (mysql_num_rows($query) != 0)
{
$rr= rand (1,10);
arr($rr);
}else{
mysql_query("INSERT INTO `url`(`url`) VALUES ('".$se."')");
return $se;
}
有效!
答案 0 :(得分:0)
查看您的url
表格。如果只获得已存储在该表中的arr
url值,则递归调用$se
函数的方式可能会无限递归。 (如果你得到一个可以转换成空字符串的值)