【问题标题】:500 Internal server error when I try to run my php script [closed]当我尝试运行我的 php 脚本时出现 500 内部服务器错误 [关闭]
【发布时间】:2015-05-04 20:29:28
【问题描述】:

当它尝试运行这个 php 脚本时

<?php
require_once 'TesseractOCR/TesseractOCR.php';

require_once 'aws_signed_request.php';

define("public_key", "****");
define("private_key", "****");
define("associate_tag", "****");

if (isset($_GET['ASIN']))
{
$ASIN = $_GET['ASIN'];
$link = "http://charts.camelcamelcamel.com/us/" . $ASIN . "/sales-rank.png?force=1&zero=0&w=400&h=400&legend=1&ilt=1&tp=1m&fo=0&lang=en";
$localurl = "../imgs/" . $ASIN . ".png";
$slocalurl = "../imgs/" . $ASIN . "-2.png";
$highrank = createSession($link, $localurl, 1);
$lowrank = createSession($link, $slocalurl, 2);
$info = ping_amazon($ASIN);
generate_response($info[0], $info[1], $lowrank, $highrank);
}
else
{
echo ('NO-ASIN');
}

function resize_and_crop($original_image_url, $thumb_image_url, $thumb_w, $thumb_h, $quality = 75)
{
$original = imagecreatefrompng($original_image_url);
if (!$original) return FALSE;
list($original_w, $original_h) = getimagesize($original_image_url);
$thumb_w_resize = $thumb_w;
$thumb_h_resize = $thumb_h;
if ($original_w > $original_h)
    {
    $thumb_h_ratio = $thumb_h / $original_h;
    $thumb_w_resize = (int)round($original_w * $thumb_h_ratio);
    }
  else
    {
    $thumb_w_ratio = $thumb_w / $original_w;
    $thumb_h_resize = (int)round($original_h * $thumb_w_ratio);
    }

if ($thumb_w_resize < $thumb_w)
    {
    $thumb_h_ratio = $thumb_w / $thumb_w_resize;
    $thumb_h_resize = (int)round($thumb_h * $thumb_h_ratio);
    $thumb_w_resize = $thumb_w;
    }

$thumb = imagecreatetruecolor($thumb_w_resize, $thumb_h_resize);
if (!imagecopyresampled($thumb, $original, 0, 0, 0, 0, $thumb_w_resize, $thumb_h_resize, $original_w, $original_h)) return FALSE;
$final = imagecreatetruecolor($thumb_w, $thumb_h);
$thumb_w_offset = 0;
$thumb_h_offset = 0;
if ($thumb_w < $thumb_w_resize)
    {
    $thumb_w_offset = (int)round(($thumb_w_resize - $thumb_w) / 2);
    }
  else
    {
    $thumb_h_offset = (int)round(($thumb_h_resize - $thumb_h) / 2);
    }

if (!imagecopy($final, $thumb, 0, 0, $thumb_w_offset, $thumb_h_offset, $thumb_w_resize, $thumb_h_resize)) return FALSE;
if (!imagepng($final, $thumb_image_url, $quality)) return FALSE;
return TRUE;
}

function createSession($link, $localurl, $imgtype)
{
copy($link, $localurl);
if ($imgtype == 1)
    {
    $sourceX = 125;
    $sourceY = 388;
    $sourceWidth = 110;
    $sourceHeight = 12;
    $destWidth = 110;
    $destHeight = 12;
    $destX = 0;
    $destY = 388;
    }
  else
    {
    $sourceX = 235;
    $sourceY = 388;
    $sourceWidth = 110;
    $sourceHeight = 12;
    $destWidth = 110;
    $destHeight = 12;
    $destX = 0;
    $destY = 388;
    }

$image = imagecreatefrompng($localurl);
$newImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
$sNewImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
imagecopyresampled($newImage, $image, 0, 0, $sourceX, $sourceY, $destWidth, $destHeight, $destWidth, $destHeight);
imagepng($newImage, $localurl, 9);
resize_and_crop($localurl, $localurl, $destWidth * 2, $destHeight * 2, 1);
imagedestroy($image);
imagedestroy($newImage);
$tesseract = new TesseractOCR($localurl);
$text = $tesseract->recognize();
$text = str_replace(" ", "", current(explode("(", $text)));
$text = str_replace(" ", "", current(explode("{", $text)));
$text = preg_replace('/[^0-9]+/', '', $text);
return $text;
}

function ping_amazon($ASIN)
{
$params = array(
    "Operation" => "ItemLookup",
    "IdType" => "ASIN",
    "ItemId" => $ASIN,
    "ResponseGroup" => "SalesRank,ItemAttributes"
);
$url = encode_info("com", $params, public_key, private_key, associate_tag);
$xml = simplexml_load_file($url);
$title = (string)$xml->Items->Item->ItemAttributes->Title;
$salesrank = (string)$xml->Items->Item->SalesRank;
$info = array(
    $title,
    $salesrank
);
return $info;
}

function generate_response($title, $salesrank, $lowrank, $highrank)
{
$average_rank = intval(($highrank + $lowrank) / 2));
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>\n";
echo "<Information>\n";
echo "<Title>" . $title . "</Title>\n";
echo "<SalesRank>" . $salesrank . "</SalesRank>\n";
echo "<LowRank>" . $lowrank . "</LowRank>\n";
echo "<HighRank>" . $highrank . "</HighRank>\n";
echo "<AverageRank>" . $average_rank . "</AverageRank>\n";
echo "</Information>";
}

?>

当我在我的计算机上使用 xampp 测试它时它可以工作,但是当我尝试在我的服务器上运行它时它不起作用。我与 ImageMagick 一起安装了 Tesseract,我所有的 php 文件都设置为 775,但我仍然收到内部服务器错误,我觉得这是因为我缺少依赖项,但老实说我不知道​​哪些依赖项。感谢您的帮助!

问题:我正在想办法解决我的内部服务器错误

【问题讨论】:

  • 首先查看您的服务器错误日志。这会告诉你错误是什么。
  • 您可以在以下位置找到 apache 日志:...\xampp\apache\logs\error.log
  • 我说当我将它与 xampp 一起使用时它工作正常,但是当我在我的服务器上使用它时它返回一个内部服务器错误 500
  • 然后检查你的服务器错误日志..
  • tesseract 编译没有错误? code.google.com/p/tesseract-ocr/wiki/Compiling。顺便说一句,如果您正在运行 xampp,您一定会遇到这些问题。运行虚拟盒子可能会更好,使用共享文件夹,并且您可以在真实环境中运行代码。

标签: php tesseract


【解决方案1】:

PHP 解析错误:语法错误,第 134 行的 test.php 中出现意外的 ')'

你在这一行多了一个)

$average_rank = intval(($highrank + $lowrank) / 2));

应该是

$average_rank = intval(($highrank + $lowrank) / 2);

【讨论】:

  • 哇,我觉得解决了我的问题很愚蠢,但现在我只需要弄清楚如何让 Tesseract 在 CentOS 上工作,对不起这个糟糕的问题。
  • 看起来你不是第一个在这方面的人stackoverflow.com/questions/23792373/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-09
  • 2017-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多