Problem using PHP in Order API

General ShopSite user discussion

Problem using PHP in Order API

Postby judodan » Fri Sep 25, 2009 12:49 pm

Hi all,

I'm trying to use PHP in the Order API (to access PHP library on back end). I've searched the forum and found some hints. I created my script to execute in the PHP CLI directly and saved it as a PL file. I accessed it directly and it worked dandy. However, when I tested buying a product, it came up with the following error:

[24-Sep-2009 16:37:05] PHP Parse error: syntax error, unexpected T_STRING in <... my path...>/shop/sc/thankyou.cgi on line 2298

Of course the thankyou.cgi file is compiled or encrypted or something...

I can put a very simple file that just echos a simple string and it still gets this error. If I pop in the CGI file, it works just fine.

my phptest.pl file looks like this:

Code: Select all
#!/usr/bin/php -q
<?php

echo "<p>Dan was here!!</p>";

?>


I'm not so good with CGI/Perl, but pretty experienced with PHP. Any help to get me up and running is MUCH appreciated...

Thanks!
-D. Israel
judodan
 
Posts: 9
Joined: Wed Sep 09, 2009 6:15 pm
Location: Richmond, CA

Postby loren_d_c » Fri Sep 25, 2009 1:20 pm

What operating system is your server using?

If Windows, then only Perl scripts and compiled executables are supported. And the Perl script must have a .pl extension (it can't be a PHP script with a .pl extension to try to trick it).

Also, even if that test script were to be executed successfully, you would probably get an Internal Server Error message instead of the thankyou screen, this is because you need to print out content type headers before you print anything else out to the browser.

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby judodan » Fri Sep 25, 2009 1:24 pm

loren_d_c wrote:What operating system is your server using?

If Windows, then only Perl scripts and compiled executables are supported. And the Perl script must have a .pl extension (it can't be a PHP script with a .pl extension to try to trick it).

Also, even if that test script were to be executed successfully, you would probably get an Internal Server Error message instead of the thankyou screen, this is because you need to print out content type headers before you print anything else out to the browser.

-Loren


I'll try adding the headers (for the test...). The system, however, is a linux system. Once I try adding the headers, I'll let you know if I get results.

Thanks for the quick pointer, I am at wit's end! :roll:
-D. Israel
judodan
 
Posts: 9
Joined: Wed Sep 09, 2009 6:15 pm
Location: Richmond, CA

Postby loren_d_c » Fri Sep 25, 2009 1:31 pm

If it is a Linux server, please give your script a normal .php file extension, there is no reason to confuse the issue by giving a .pl extension when it is really a PHP script.

Of course it shouldn't hurt anything either, since from the commandline Linux doesn't execute files based on their file extension anyway.

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby judodan » Fri Sep 25, 2009 1:37 pm

loren_d_c wrote:If it is a Linux server, please give your script a normal .php file extension, there is no reason to confuse the issue by giving a .pl extension when it is really a PHP script.

Of course it shouldn't hurt anything either, since from the commandline Linux doesn't execute files based on their file extension anyway.

-Loren


OK... I still have to put the #!/usr/bin/php -q at the beginning, right?

I know this is unrelated, but is there some way to test this from an order without actually placing an order? I could not seem to find a way to do it on a demo store (which actually makes sense...) but I'd like to not have to run up a bunch of orders testing and ask the client to refund them...
-D. Israel
judodan
 
Posts: 9
Joined: Wed Sep 09, 2009 6:15 pm
Location: Richmond, CA

Postby judodan » Fri Sep 25, 2009 2:13 pm

ok, so I added the context type and changed the extension.

Still getting the same error. Hrm. Any other ideas??

Thanks.

(Code now looks like so:
Code: Select all

#!/usr/bin/php -q
<?php

echo "Content-type: text/html\n\n";

echo "Dan was here!!";
?>

)
-D. Israel
judodan
 
Posts: 9
Joined: Wed Sep 09, 2009 6:15 pm
Location: Richmond, CA

Postby loren_d_c » Fri Sep 25, 2009 3:24 pm

Are you sure you are using a CLI-enabled version of PHP or that executing PHP from the commandline isn't disabled by some global PHP setting?

Have you tried running the script by itself from the commandline (not from your browser)?

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby judodan » Fri Sep 25, 2009 3:31 pm

loren_d_c wrote:Are you sure you are using a CLI-enabled version of PHP or that executing PHP from the commandline isn't disabled by some global PHP setting?

Have you tried running the script by itself from the commandline (not from your browser)?

-Loren


No access to command line, but I popped it in as a CRON job and it runs, so I presume that's it's enabled.
-D. Israel
judodan
 
Posts: 9
Joined: Wed Sep 09, 2009 6:15 pm
Location: Richmond, CA

Postby loren_d_c » Fri Sep 25, 2009 3:55 pm

Try starting your PHP with this code:

$query_string = trim(fgets(STDIN));
parse_str($query_string,$params);

It may be that your script is finishing and exiting too fast. This should slow it down a little bit by making sure it waits until after it has received all of the parameters from ShopSite before it completes and exits.

-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere

Postby loren_d_c » Fri Sep 25, 2009 3:57 pm

Here is an example PHP script that works for me via the Order API:


Code: Select all
#!/usr/bin/php -q
<?php
$query_string = trim(fgets(STDIN));
parse_str($query_string,$params);

echo "Content-type: text/html\n\n";
?>

<head>
<title>Test</title>
</head>
<body>This is a test!</body>


-Loren
loren_d_c
 
Posts: 2572
Joined: Fri Aug 04, 2006 12:02 pm
Location: Anywhere


Return to User Forum

Who is online

Users browsing this forum: No registered users and 130 guests