drpitman / PHP-Xero

A php class to interact with the Xero API
29 stars 73 forks source link

Problem with $xero->Payments #7

Open swordfox opened 13 years ago

swordfox commented 13 years ago

All methods seem to work fine except $xero->Payments

The screen just goes blank after calling the following method with print_r. I've PHP error values set to show all & it's still blank.

$payment_result = $xero->Payments( $new_payment ); print_r($payment_result);

Any ideas?

nickteagle commented 13 years ago

Hi I've just starting using this and I get a Segmentation fault (i'm test using the command line) when adding a new payment but both adding a new Contact and Invoice and listing my Accounts all work fine. I've also emailed xero to see if its anything at there end Note the xero status for these are 400 but i can't see anything wrong. It crash's here $xero_response = curl_exec($ch) (line 309 approx) I've also copy my code to my laptop which is a ubuntu 10.10 php 5.3.3 and it crash's on there as well.

Nick

relaxomatic commented 13 years ago

I seem to be having the same issue, what I have noticed is that on my development machine which runs windows 7 it works fine, but on our production machine which runs Debian it is having issues when it reaches that line $xero_response = curl_exec($ch).

nickteagle commented 13 years ago

I've got mine to work by using fsocket for the put message if you email me I can send you my xero.php. nickteagle (at) gmail.com. I'm also tried installing the latest version of php and curl and I still have the error so i'm going to raise a bug on curl and see if that helps. Nick

davidmytton commented 13 years ago

I've commited Nick's fix for this here: https://github.com/dmytton/PHP-Xero/commit/054c45906aa1d9d0b70d49ed133081464810436a

eugeneius commented 13 years ago

What's happening is that the memory-mapped file is closed before curl has a chance to read it - it's a problem with the xero library, not curl. Here's a patch:

diff --git a/xero.php b/xero.php
index 3afa43d..1215780 100644
--- a/xero.php
+++ b/xero.php
@@ -303,10 +303,13 @@ class Xero {
                                curl_setopt($ch, CURLOPT_INFILE, $fh);
                                curl_setopt($ch, CURLOPT_INFILESIZE, strlen($xml));
                                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
-                               fclose($fh);
                        }
                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                        $xero_response = curl_exec($ch);
+                       if (isset($fh))
+                       {
+                               fclose($fh);
+                       }
                        $xero_xml = simplexml_load_string( $xero_response );
                        if (!$xero_xml) {
                                return $xero_response;

I've opened a new pull request (#13) with this change as well.

calvinfroedge commented 12 years ago

Thanks for posting this fix. Much obliged.