PHP Barcode API error 505

  • 5.7K Views
  • Last Post 12 January 2013
dumbproducts posted this 21 December 2012

When I try to run the PHP code below, it jutst loads... and loads... and then after about 2 minutes it displays: "Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.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.". And my server's configured!!! The image I'm attempting to decode: http://dumbsearch.com/dumbocr/qr.png

Here's the code, it's a slightly modified version of the sample code:

    <?php
  // Enter your data here.
  // You need an Application ID and Application Password,
  // which can be created during registration.
  // If you are not registered yet, register
  // on http://www.abbyyonline.com/en/Account/LogOn?service=ocrsdk.
  // Application ID and Application Password are passed
  // to Cloud OCR server with each request.
  $applicationId = 'dumbsearc';
  $password = '***PASSWORD****';
  $fileName = 'qr.png';

  ////////////////////////////////////////////////////////////////
  // 1.a Send an image with barcodes to Cloud OCR server
  //     using processImage call
  //     with barcodeRecognition profile as a parameter,
  //     or
  // 1.b Send an image of a barcode to Cloud OCR server
  //     using processBarcodeField call.
  // 2.  Get response as XML.
  // 3.  Read taskId from XML.
  ////////////////////////////////////////////////////////////////

  // Get path to the file that you are going to process.
  $local_directory=dirname(__FILE__).'';

  // Using the processImage method.
  // Use barcodeRecognition profile to extract barcode values.
  // Save results in XML (you can use any other available output format).
  // See details in API Reference.
  $url = 'http://cloud.ocrsdk.com/processImage?profile=barcodeRecognition&exportFormat=xml';

  // Using the processBarcodeField method.
  // Specify the region of a barcode (by default, the whole image is recognized),
  // barcode type, and other parameters.
  // See details in API Reference.
  // $url = 'http://cloud.ocrsdk.com/processBarcodeField?barcodeType=qrCode';

  // Send HTTP POST request and get XML response.
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password");
  curl_setopt($ch, CURLOPT_POST, 1);
  $post_array = array(
    "my_file"=>"@".$local_directory.'/'.$fileName,
  );
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array);
  $response = curl_exec($ch);
  curl_close($ch);

  // Parse XML response.
  $xml = simplexml_load_string($response);
  $arr = $xml->task[0]->attributes();

  // Task id.
  $taskid = $arr["id"];

  /////////////////////////////////////////////////////////////////
  // 4. Get task information in a loop until task processing finishes.
  // 5. If response contains "Completed" status, extract URL with result.
  // 6. Download recognition result.
  /////////////////////////////////////////////////////////////////

  $url = 'http://cloud.ocrsdk.com/getTaskStatus';
  $qry_str = "?taskid=$taskid";

  // Check task status in a loop until it is "Completed".
  do
  {
    sleep(5);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.$qry_str);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password");
    $response = curl_exec($ch);
    curl_close($ch);

    // Parse XML.
    $xml = simplexml_load_string($response);
    $arr = $xml->task[0]->attributes();
  }
  while($arr["status"] != "Completed");

  // Result is ready. Download it.

  $url = $arr["resultUrl"];
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $response = curl_exec($ch);
  curl_close($ch);

  // Parse output XML to extract barcode values.
  // Note that output XML files have different structure
  // depending on the method you used for processing.
?>

Thank you so much!

Order By: Standard | Newest | Votes
Dmitry Me posted this 24 December 2012

Which line specifically yields the error message?

dumbproducts posted this 24 December 2012

No line shows any error, the page keeps loading, and loading, and then finally after about a few minutes, a message apears saying that my apache server is misconfigured, which it isn't.

Dmitry Me posted this 25 December 2012

Is there any output from the sample code? What's the last thing that works and what's the first thing that doesn't work?

dumbproducts posted this 12 January 2013

It appears to work now. Thanks for your interest.

Close