markhartnady
02-04-2004, 04:21 PM
It's 5:30pm. Everyone is leaving the office. But I cant cos this page keeps crashing Apache.
I know nothing about caching or output buffering but this may be the solution to the problem.
I am trying to run a script, which returns about 3,000 records from a MySQL db each containing a URL. On each URL, I am running a function. This takes about 2-4 seconds per URL. So in essence the whole page should take about (3X3000sec = +- 2 hours). This is fine, as I can leave it running overnight, but it keeps timing out.
After about 4 minutes, Apache returns an error and the page stops running.
Heres the code:
<?php
error_reporting(0);
//$fp = fsockopen($url, 80, $errno, $errstr, 30);
include "ez_sql.php";
include "Smarty.class.php";
function format_url ($url) {
$scheme = substr($url, 0, 4);
if ($scheme <> "http") { //cater for https also
$t_url = "http://" . $url;
return $t_url;
} else { return $url; }
}
function is_deadlink ($url) {
$t_url = format_url($url);
$fp = fopen($t_url, "r");
if (!$fp) { return true; }
else { return false; }
}
$sql_sl = "SELECT t1.id_sl_folder as folder_id, t2.id_sl_link as link_id,
trim( t3.url ) AS myurl,
t3.active, t3.system_active, count(t2.id_sl_link) as count_link_id
FROM tb_sl_folder AS t1
LEFT JOIN tb_sl_folder_link AS t2 ON t1.id_sl_folder = t2.id_sl_folder
LEFT JOIN tb_sl_link AS t3 ON t3.id_sl_link = t2.id_sl_link
WHERE t3.url <> ''
GROUP BY t3.url
ORDER BY t3.url";
$result = mysql_query($sql_sl);
header('X-pmaPing: Pong');
ini_set("max_execution_time", "3000");
ob_start();
?>
<HTML>
<head>
<link href="../css/pmapsadmin.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<font class="dfont10"><b>
<?
$sing_links = 0;
$totallinks = 0;
while ($row = mysql_fetch_array($result))
{
$totallinks += $row["count_link_id"];
$sing_links += 1;
}
echo "Total no. links: " . $totallinks . "<BR>";
echo "Total no. unrepeated links: " . $sing_links . "<BR>";
echo "Please be patient, this query can take up to 15 minutes.<BR><BR>";
ob_end_flush();
ob_start();
$result = mysql_query($sql_sl);
while ($url_array = mysql_fetch_array($result))
{
$currsl = $url_array["folder_id"];
$id_sl_link = $url_array["link_id"];
echo "Edit Link: <a target=_BLANK href=\"smartlinks_admin.php?currsl=$currsl&op=EditLink&id_sl_link=$id_sl_link\">" . $url_array["link_id"] . "</a>";
echo " URL: <a target=_BLANK href=\"" . format_url($url_array["myurl"]) . "\">" . $url_array["myurl"] . "</a> ";
if (is_deadlink(format_url($url_array["myurl"]))) {
$status = "<font color=red>DEAD</font>";
} else { $status = "<font color=green>ACTIVE</font>"; }
echo "Link is: $status<br>";
}
?>
</b></font>
</body>
</HTML>
<?
ob_end_flush();
?>
I know nothing about caching or output buffering but this may be the solution to the problem.
I am trying to run a script, which returns about 3,000 records from a MySQL db each containing a URL. On each URL, I am running a function. This takes about 2-4 seconds per URL. So in essence the whole page should take about (3X3000sec = +- 2 hours). This is fine, as I can leave it running overnight, but it keeps timing out.
After about 4 minutes, Apache returns an error and the page stops running.
Heres the code:
<?php
error_reporting(0);
//$fp = fsockopen($url, 80, $errno, $errstr, 30);
include "ez_sql.php";
include "Smarty.class.php";
function format_url ($url) {
$scheme = substr($url, 0, 4);
if ($scheme <> "http") { //cater for https also
$t_url = "http://" . $url;
return $t_url;
} else { return $url; }
}
function is_deadlink ($url) {
$t_url = format_url($url);
$fp = fopen($t_url, "r");
if (!$fp) { return true; }
else { return false; }
}
$sql_sl = "SELECT t1.id_sl_folder as folder_id, t2.id_sl_link as link_id,
trim( t3.url ) AS myurl,
t3.active, t3.system_active, count(t2.id_sl_link) as count_link_id
FROM tb_sl_folder AS t1
LEFT JOIN tb_sl_folder_link AS t2 ON t1.id_sl_folder = t2.id_sl_folder
LEFT JOIN tb_sl_link AS t3 ON t3.id_sl_link = t2.id_sl_link
WHERE t3.url <> ''
GROUP BY t3.url
ORDER BY t3.url";
$result = mysql_query($sql_sl);
header('X-pmaPing: Pong');
ini_set("max_execution_time", "3000");
ob_start();
?>
<HTML>
<head>
<link href="../css/pmapsadmin.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF">
<font class="dfont10"><b>
<?
$sing_links = 0;
$totallinks = 0;
while ($row = mysql_fetch_array($result))
{
$totallinks += $row["count_link_id"];
$sing_links += 1;
}
echo "Total no. links: " . $totallinks . "<BR>";
echo "Total no. unrepeated links: " . $sing_links . "<BR>";
echo "Please be patient, this query can take up to 15 minutes.<BR><BR>";
ob_end_flush();
ob_start();
$result = mysql_query($sql_sl);
while ($url_array = mysql_fetch_array($result))
{
$currsl = $url_array["folder_id"];
$id_sl_link = $url_array["link_id"];
echo "Edit Link: <a target=_BLANK href=\"smartlinks_admin.php?currsl=$currsl&op=EditLink&id_sl_link=$id_sl_link\">" . $url_array["link_id"] . "</a>";
echo " URL: <a target=_BLANK href=\"" . format_url($url_array["myurl"]) . "\">" . $url_array["myurl"] . "</a> ";
if (is_deadlink(format_url($url_array["myurl"]))) {
$status = "<font color=red>DEAD</font>";
} else { $status = "<font color=green>ACTIVE</font>"; }
echo "Link is: $status<br>";
}
?>
</b></font>
</body>
</HTML>
<?
ob_end_flush();
?>