SOLVED: Order API via PHP = Internal Server Error

General ShopSite user discussion

SOLVED: Order API via PHP = Internal Server Error

Postby kyleh » Mon Jan 03, 2011 9:42 am

Hello,

I have an order API script that uses PHP to parse the order data from Shopsite. I've used this script for a couple years on a different Verio VPS without any issues. I recently upgraded to the latest Shopsite and moved to a new VPS at Verio without migrating the old store to the new. I loaded all of the settings, pages and products from scratch in the new store. Everything is working fine other that the order api script (and Shopsite not being able to fine sendmail for order confirmations).

When I use my php script for the order api the script executes (order data is sent to my fulfillment center) then throws a 500 Internal server error when trying to go the the thankyou.cgi. When I check my error logs I see a ambiguous malformed header error. If I use the perl test script everything works fine.

I shortened my script for testing purposes to the following:
Code: Select all
#!/usr/local/bin/php
<?php
$query_string = trim(fgets(STDIN));
parse_str($query_string, $order);
?>


Is there any reason why a PHP CLI script will execute when called then throw the 500 External Server Error when trying to go the the thankyou.cgi? I've also tested executing PHP scripts from the command line in the same directory (cig-bin/sc/) with the same permissions (755) without an issue. Could there be some disconnect between the CLI PHP and the Apache PHP?

This one has me stumped. Any help would be greatly appreciated.

Thanks,

Kyle
Last edited by kyleh on Mon Jan 03, 2011 11:52 am, edited 1 time in total.
kyleh
 
Posts: 4
Joined: Tue Aug 03, 2010 12:08 pm
Location: Colorado, USA

Re: Order API via PHP = Internal Server Error

Postby robm » Mon Jan 03, 2011 10:18 am

The malformed header means PHP is outputting characters to STDOUT, which in the case of an order API script means it's writing to the web browser. Make sure your script is suppressing all warnings and notices, and no output is generated. If it needs to generate output, make sure a valid html header is sent first.

Rob
robm
 
Posts: 463
Joined: Fri Aug 04, 2006 5:46 pm
Location: Connecticut

Re: Order API via PHP = Internal Server Error

Postby kyleh » Mon Jan 03, 2011 11:28 am

Thanks for your reply Rob. I also have several sites hosted on Lexiconn and recall emails with you from time to time. That's what I thought but all my efforts to surpress any output from the script still throw the error.

Example:
Code: Select all
#!/usr/local/bin/php -q
<?php
ob_start();
//open by default
fclose('php://stdout');
error_reporting(E_ERROR);
$query_string = trim(fgets(STDIN));
parse_str($query_string,$order);
ob_end_clean();
?>


If I test a Perl script and intentionally have it print to the screen it will output to the browser and happily execute thankyou.cgi.

Code: Select all
#!/usr/local/bin/perl
print 'Your order was successful';
kyleh
 
Posts: 4
Joined: Tue Aug 03, 2010 12:08 pm
Location: Colorado, USA

Re: Order API via PHP = Internal Server Error

Postby kyleh » Mon Jan 03, 2011 11:51 am

In case anyone runs into this problem in the future adding the following to the beginning of my script solved the problem.

Code: Select all
#!/usr/local/bin/php
<?php
fclose(STDOUT);
$query_string = trim(fgets(STDIN));
parse_str($query_string,$order);
?>


The fclose(STDOUT) at the beginning of the script was the key. I didn't need any of the ob functions. The old server was running 4.x version of PHP. The new server 5.2.
kyleh
 
Posts: 4
Joined: Tue Aug 03, 2010 12:08 pm
Location: Colorado, USA


Return to User Forum

Who is online

Users browsing this forum: No registered users and 18 guests