Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a PHP app running on a cloud-based Ubuntu server and for some reason, I am getting a newline at the start of every HTML file or XHR response.

I have a local version of the app running on Ubuntu, and this newline does not appear.

Specifically, the bad responses have one additional character with ASCII code 10 prepended to each response.

This is causing my Javascript to break because the XHR object won't recognize the XHR responses as XML because of the leading newline character.

I am using the Agavi framework, version 0.9.2 (yes, old!) as the PHP web framework. I have been able to insert echo statements into my custom Views and the newline still appears first in the response.

So is it Apache or Agavi or something else doing this?

Any thoughts?

Thanks.

share|improve this question
    
Is the XHR coming as UTF-8? It could be some confusion over a byte-order mark or canonicalized decomposition... –  hexafraction Aug 14 '12 at 19:45
    
I put a breakpoint in the JavaScript code that handles the XHR response, and examined the full text of the response, as follows: var x = Request.response; x.charCodeAt(0); Prints: 10 So it's a newline character. –  Jacob Toronto Aug 14 '12 at 20:29
    
I added a php_value to my Apache config: php_value auto_prepend_file /home/ubuntu/pound.php Contents of pound.php: ### After reloading my apache config, the XHR response has the three pound symbols before the newline character. So somewhere between PHP's auto_prepend processor and my Agavi view processor, I'm getting the newline. –  Jacob Toronto Aug 14 '12 at 20:37
    
I have never worked with the Agavi frameowrk. Sorry. Maye you could try Stack Overflow? –  hexafraction Aug 15 '12 at 12:05

1 Answer 1

I experienced a similar problem which may or may not be related. I found that the culprit was whitespace in the PHP code. To rectify this, however, you need to be able to review and change the source code. To avoid ths kind of problem in PHP, it is a good idea to skip using the closing ?> tag (after which whitespace inadvertently can be inserted).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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