0

I have a Magento v1.8.0 site that's been running fine for over a year. We're moving the site from one hosting server to another and are experiencing some problems. I'm hoping someone can point me in the right direction in terms of what might be causing the issue I'm experiencing.

The is issue is as such. A user checking out sometimes receives the following error after clicking the checkout button (before being sent to PayPal).

URL: https://www.example.com:443/paypal/express/start/
IP Address: x.x.x.x
Time: 2014-12-31 17:15:56 GMT
Error:
Cannot send headers; headers already sent in /home/example/public_html/app/code/core/Mage/Sales/Model/Order.php, line 1

Trace:
#0 /home/example/public_html/lib/Zend/Controller/Response/Abstract.php(158): Zend_Controller_Response_Abstract->canSendHeaders(true)
#1 /home/example/public_html/app/code/core/Mage/Core/Controller/Response/Http.php(106): Zend_Controller_Response_Abstract->setRedirect('https://www.exa...', 302)
#2 /home/example/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(712): Mage_Core_Controller_Response_Http->setRedirect('https://www.exa...')
#3 /home/example/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(690): Mage_Core_Controller_Varien_Action->setRedirectWithCookieCheck('checkout/cart', Array)
#4 /home/example/public_html/app/code/core/Mage/Paypal/Controller/Express/Abstract.php(103): Mage_Core_Controller_Varien_Action->_redirect('checkout/cart')
#5 /home/example/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Paypal_Controller_Express_Abstract->startAction()
#6 /home/example/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('start')
#7 /home/example/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#8 /home/example/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#9 /home/example/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#10 /home/example/public_html/index.php(87): Mage::run('', 'store')
#11 {main}

Sometimes this works, but not usually (making this even stranger). If the user hits refresh he is sent to PayPal and able to complete his order. On return to the Review page a Magento error is displayed saying "Unable to initialize Express Checkout." I believe this to be an error generated before the unsuccessful redirect to PayPal and it's just left over in the session. The user can then click "Place Order" which generates the same error as before. This error always occurs. The order is correctly placed. We can see it in the backend and order emails are sent out. It's almost like it's not redirecting appropriately (probably because headers are being sent from a different process in the chain).

The site works perfectly on the old server, but not on the new. The code is exactly the same, the database is exactly the same, permissions are exactly the same. It's clearly some kind of difference, but I'm unable to figure out a way to troubleshoot this to give me an idea of where to look (like a warning or something that's being generated that's causing output).

Both errors are thrown when we get to $this->canSendHeaders(true); in the following code snippet from lib/Zend/Controller/Response/Abstract.php

/**
 * Set redirect URL
 *
 * Sets Location header and response code. Forces replacement of any prior
 * redirects.
 *
 * @param string $url
 * @param int $code
 * @return Zend_Controller_Response_Abstract
 */
public function setRedirect($url, $code = 302)
{
    $this->canSendHeaders(true);
    $this->setHeader('Location', $url, true)
         ->setHttpResponseCode($code);

    return $this;
}

The versions of packages are slightly different, however I have two other Magento sites that have been migrated successfully with no issues (however, those are Magento 1.6 and 1.7).

Old Server
Apache 2.2.27
PHP 5.4.30
MySQL 5.5.32

New Server
LiteSpeed 4.2.19
PHP 5.4.35
MySQL 5.5.40

So far I have attempted the following:

  • Modifying lib/Zend/Controller/Response/Abstract.php to show headers just before the error and then exit (so I can see them).
  • Modifying lib/Zend/Controller/Response/Abstract.php to output the output buffer using echo ob_get_contents(); just before the error and then exit (so I can see any generated output). No output is displayed.

Any help tracking this down (or even providing ways in which I might be able to troubleshoot the issue) would be greatly appreciated!

closed as off-topic by Marius Jan 1 '15 at 11:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Marius
If this question can be reworded to fit the rules in the help center, please edit the question.

  • You're right. I was able to find my own answer eventually and it really had nothing to do with magento. PHP did not have output buffering turned on the new server which didn't play nice with the site in question. Turning output buffering on fixed my problem. – Jeremy Driscoll Jan 4 '15 at 6:35
  • I don't have enough reputation to answer my own question, so please let me know how I should proceed with this question. – Jeremy Driscoll Jan 4 '15 at 6:36
1

Please check if you have any spaces or new lines before opening php tag (<?php) in app/code/core/Mage/Sales/Model/Order.php and remove them. Also check if this file is in UTF-8 without BOM encoding and UNIX end of line format.

If you have Notepad++ you can see this in the right bottom corner and you can change it in Encoding -> Convert to UTF-8 without BOM and Edit -> EOL Conversion -> UNIX Format. Or every other more advanced text editor or IDE has such options.

  • +1vote,this basic issue in unix system. i have face several times – Amit Bera Jan 1 '15 at 6:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.