Re: script dies yet there are no errors in error log



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);


?>


.



Relevant Pages

  • Re: script dies yet there are no errors in error log
    ... This script dies after processing about 20 or 25 ... maybe 7 per UPC code. ... a little memory in PHP - but also results in a call to MySQL to free ... realized the whole, long, complicated whileloop could be rewritten ...
    (comp.lang.php)
  • Re: Confused About PHP!?
    ... this example script then just cut and past the iinput elements into ... I am creating a site in FrontPage, and want to use PHP to validate a form I ... to return on a plain HTML page (without any site design features). ... already in the database. ...
    (comp.lang.php)
  • Re: Newbie Security Questions
    ... with $username and $password defined elsewhere in the source file. ... as you'd be a fool to have your database server ... went hunting through my html and found the php script they could ... more rights to a script than it needs. ...
    (comp.lang.php)
  • Re: What Next?
    ... PHP, but it has far fewer built-in functions, which makes it a bit neater ... For example, if you need to use a database, there are built-in database ... I came from Perl to PHP (which is not to say that I don't still use Perl ... form fields against a server script in a javascript "onblur" event. ...
    (comp.lang.php)
  • Re: Error 444 Script or Action Blocked
    ... This is a relatively simple script. ... and compares it to a tab-delimited flat-text database. ... The only real PHP code in the script is as follows: ... It may not solve your problem, but it will fix another potential problem you can have with some browsers. ...
    (comp.lang.php)