我已经经历了所有类似的问题,没有什么符合法案。php脚本执行但没有输出
我正在运行一个大脚本,它在旧服务器上的chron上运行,但未能在新服务器上运行,因此我正在使用并在浏览器中进行测试。
我有两个函数,一个从数据库中提取属性,然后通过另一个运行它们,将价格转换为4种货币,如果值不同,则更新该行。功能如下:
<?php
function convert_price($fore_currency, $aft_currency, $amount)
{
echo "going into convert<br/>";
$url = "http://www.currency.me.uk/remote/ER-ERC-AJAX.php?ConvertFrom=" . $fore_currency .
"&ConvertTo=" . $aft_currency . "&amount=" . $amount;
if (!is_int((int)file_get_contents($url))) {
//echo "Failed on convert<br/>";
return false;
} else {
//echo "Conversion done";
return (int)file_get_contents($url);
}
}
function run_conversion($refno = '', $output = false)
{
global $wpdb;
$currencies = array("GBP", "EUR", "TRY", "USD");
$q = "SELECT * FROM Properties ";
$q .= (!empty($refno)) ? " WHERE Refno='" . $refno . "'" : "";
$rows = $wpdb->get_results($wpdb->prepare($q), ARRAY_A);
$currencies = array("USD", "GBP", "TRY", "EUR");
//$wpdb->show_errors();
echo "in Run Conversion " . "<br/>";
foreach ($rows as $row) {
echo "In ROw <br/>";
foreach ($currencies as $currency) {
if ($currency != $row['Currency'] && $row['Price'] != 0) {
$currfield = $currency . "_Price";
$newprice = convert_price($row['Currency'], $currency, $row['Price']);
echo "Old Price Was " . $row['Price'] . " New Price Is " . $newprice . "<br/>";
if ($newprice) {
if ($row[$currfield] != $newprice) {
$newq = "UPDATE Properties SET DateUpdated = '" . date("Y-m-d h:i:s") . "', " .
$currfield . "=" . $newprice . " WHERE Refno='" . $row['Refno'] . "'";
$newr = $wpdb->query($newq);
if ($output) {
echo $newq . " executed <br/>";
} else {
echo "query failed " . $wpdb->print_error();
}
} else {
if ($output) {
echo "No need to update " . $row['Refno'] . " with " . $newprice . "<br/>";
}
}
} else {
echo "Currency conversion failed";
}
}
}
}
}
?>
然后,我从一个单独的文件运行过程中对历代志的缘故,像这样:
require($_SERVER['DOCUMENT_ROOT'] . "/functions.php"); // page containing functions
run_conversion('',true);
如果我限制MySQL查询100级性能运行良好,并我在一个很好的流中获得所有输出。但是当我尝试完全运行脚本时,脚本完成(我可以从db中更新的行中看到)但没有输出。我已经尝试提高记忆容量,但没有快乐。任何想法感激地收到。另外,从Apache模块更改为CGI时,我得到一个500错误。任何关于这个想法的想法也很受欢迎,因为我希望将网站变成fastCGI。
你应该看看错误日志。 – 2011-12-18 18:34:45
'$ _SERVER ['DOCUMENT_ROOT']'假定HTTP,你提到Apache,但你说它是一个cron脚本。 cron与此有关吗? – 2011-12-18 18:35:22
你确定它正在完成所有更新?这可能是脚本达到了max_execution_time? – nachito 2011-12-18 18:40:56