Re: script dies yet there are no errors in error log
- From: gordonb.k1qz1@xxxxxxxxxxx (Gordon Burditt)
- Date: Tue, 21 Oct 2008 10:58:41 -0500
What does the query
select upc_id, count(upc_id) from `albums` group by upper(upc_id);
return? Does it indicate any duplicates? How long does it take to run?
It might be better to ensure the case of the entries in the database,
(say, with update `albums` set upc_id = UPPER(upc_id); , then make
sure anything later inserted is converted to upper case first,
and change WHERE UPPER(upc_id) = ... to WHERE upc_id = ... .
as it may permit using indexes better.
Do the indexes slow down UPDATEs?
Slightly.
When I attempt to input 200 UPCs, I don't even get a PHP error, instead
I get this error:
"OK
The server encountered an internal error or misconfiguration and was
unable to complete your request.
This kind of error usually is caused by a CGI or PHP failing to
output headers at all (e.g. core dump), or putting out malformed
headers (PHP is pretty good about putting out real headers before
other stuff, but in a CGI a warning/error message before headers
can do this). It may also be caused by permission problems on a
CGI (either too restrictive to execute, or too generous with write
permission to be safe to execute) but this is not usually applicable
to PHP.
Please contact the server administrator and inform them of the time the
error occurred, and anything you might have done that may have caused
the error.
More information about this error may be available in the server error log.
Apache/2.2.3 (CentOS) Port 443"
As I mentioned before, no errors show up in PHP error log.
What error log did the error message mention? Not PHP.
// 10-20-08 see comment above to see why empty string is dangerous
- returns 10,147 rows!
*WHY* are those 10,147 rows even in the database?
if ($upc != "") {
$upc = trim($upc);
fwrite($fp, $upc."\n");
echo "<br /> \n <br /> \n Removing UPC/ISRC Code: $upc ";
$query = "UPDATE albums SET status=4 WHERE UPPER(upc_id) =
'".strtoupper($upc)."'";
$result = mysql_query($query);
echo "<br /> \n albums updated: " . mysql_affected_rows();
$query = "UPDATE tracks SET status=4 WHERE UPPER(isrc_id) =
'".strtoupper($upc)."'";
$result = mysql_query($query);
echo "<br /> \n tracks updated: " . mysql_affected_rows();
}
echo "<br />";
} // ends for() loop
fclose($fp);
$endTime = microtime();
echo "<p>End time: $endTime </p>";
$totalTime = $endTime - $startTime;
$totalTime = round($totalTime / 1000, 2);
echo "The total time for this script was $totalTime seconds";
}
The input for this script is coming from a textarea in a form, and the
input could not be more simple, just a bunch of UPC codes, one per line:
881034146533x
881034146533xx
881034146533xxx
881034146533xxxx
881034146533xxxxx
881034146533xxxxxx
881034146533xxxxxxx
881034146533xxxxxxxx
881034146533xxxxxxxxx
881034146533xxxxxxxxxx
881034146533xxxxxxxxxxx
881034146533xxxxxxxxxxxx
881034146533xxxxxxxxxxxxx
881034146533xxxxxxxxxxxxxx
881034146533xxxxxxxxxxxxxxx
881034146533xxxxxxxxxxxxxxxx
881034146533xxxxxxxxxxxxxxxxx
881034146533xxxxxxxxxxxxxxxxxx
Given 15 such numbers, the script does fine. But given 200 such numbers,
it dies after processing about 10 numbers.
Supposedly, the code was written many years ago, back in 2002, and yet,
supposedly, the problem with this script (that it dies) only started
recently. Supposedly, no changes were made to the script, it simply
started to die. (Sadly, the code for the site was only recently put into
Subversion, and I only recently joined the project, so I've no way to
evaluate these claims.)
Did you recently set up the database on a different system, and perhaps
forget to put in the indexes? Could duplicate records be piling up?
<?
set_time_limit(0);
require ("include_header.php");
$dbh = mysql_pconnect("xxxxx", "xxxxx", "xxxxx");
mysql_select_db("alb");
$upc_input = $_POST["upc_input"];
if ($upc_input) {
$pieces = explode("\n", $upc_input);
$count = 0;
$log_file = dirname($_SERVER["SCRIPT_FILENAME"]).'/logs/album_removals.log';
$fp = fopen($log_file, 'a+');
while ($upc = $pieces[$count]) {
$upc = trim($upc);
fwrite($fp, $upc."\n");
echo "Removing UPC/ISRC Code: $upc <br />\n";
$query = "select id from `albums` where UPPER(upc_id) =
'".strtoupper($upc)."'";
$result = mysql_query($query);
if (mysql_num_rows($result)) {
// 10-15-08 - this next line makes the assumption that there can
only be
// one record for each UPC. Since I don't know enough to argue, I'll
// assume this must be true for now. I wonder if the import scripts
// enforce uniqueness on the UPC? --LK
$row = mysql_fetch_array($result);
$id = $row["id"];
/* We changed this to status='4' to indicate full removal.
Only values of status='3' will be checked when we run
our go_live.php cronjob to set albums live on certain dates
*/
$query2 = "update albums SET status='4' where id=".$id;
$result2 = mysql_query($query2);
$numUpdated = mysql_affected_rows($dbh);
if ($numUpdated) {
echo "Changed album status for UPC $id <br />\n";
} else {
// echo "Failed to change album status for UPC $id <br />\n ";
//
// 10-15-08 - what happens when some staffer puts the same UPC in
twice? I don't
// want to give a "fail" message. Let's check to see the status.
If it equals 4
// then the record has already been successfully updated. If not,
then we can
// give a fail message.
$queryStatusCheck = "SELECT status FROM albums WHERE id='$id' ";
$resultStatusCheck = mysql_query($queryStatusCheck);
$rowStatusCheck = mysql_fetch_assoc($resultStatusCheck);
$status = $rowStatusCheck["status"];
if ($status == 4) {
echo "Album status already updated <br />\n ";
} else {
echo "Failed to change album status for UPC $upc (album $id)
<br />\n ";
}
}
$query3 = "update tracks SET status='4' where album_id=".$id;
$result3 = mysql_query($query3);
$numUpdated = mysql_affected_rows($dbh);
if ($numUpdated) {
echo "Changed tracks album status for UPC $id <br /><br />\n\n ";
} else {
// echo "Failed to change tracks album status for UPC $id <br
/><br />\n\n ";
//
// 10-15-08 - what happens when some staffer puts the same UPC in
twice? I don't
// want to give a "fail" message. Let's check to see the status.
If it equals 4
// then the record has already been successfully updated. If not,
then we can
// give a fail message.
$queryStatusCheck = "SELECT status FROM tracks WHERE
album_id='$id' ";
$resultStatusCheck = mysql_query($queryStatusCheck);
$rowStatusCheck = mysql_fetch_assoc($resultStatusCheck);
$status = $rowStatusCheck["status"];
if ($status == 4) {
echo "Track album status already updated <br />\n ";
} else {
echo "Failed to change track album status for UPC $upc (album
$id) <br />\n ";
}
}
} else {
$query = "select id from `tracks` where UPPER(isrc_id) =
'".strtoupper($upc)."'";
$result = mysql_query($query);
if (mysql_num_rows($result)) {
$row = mysql_fetch_array($result);
$id = $row["id"];
$query2 = "update tracks SET status='4' where id=".$id;
$result2 = mysql_query($query2);
echo "Successfully removed and rebuilt Track Id ".$id;
} else {
echo "Could not find Code as an Album UPC or a Track ISRC";
}
}
echo "<br />";
$count++;
}
fclose($fp);
?>
.
- References:
- script dies yet there are no errors in error log
- From: Lawrence Krubner
- Re: script dies yet there are no errors in error log
- From: Gordon Burditt
- Re: script dies yet there are no errors in error log
- From: Lawrence Krubner
- script dies yet there are no errors in error log
- Prev by Date: Re: script dies yet there are no errors in error log
- Next by Date: Re: ********Caution Newbie********editing and deleting from mysql database
- Previous by thread: Re: script dies yet there are no errors in error log
- Next by thread: Re: script dies yet there are no errors in error log
- Index(es):
Relevant Pages
|