Web Services on Ubuntu

I have been running an app using the Yii framework on a linux server hosted on GoDaddy, I recently have moved that app to a dedicated server running Ubuntu. I ran into a problem where the XML for my WSDL wouldn’t parse. It complained of having extra whitespace before the XML Declaration. To fix this, I modified the Yii Framework to do an ob_clean() call just before writing the XML response out, and things worked. So I think somewhere in the framework an extra space is being output under Ubuntu that isn’t on other platforms. I’m fairly sure that I’m not doing anything to cause the extra noise to be sent in the app code. Sound like a Yii framework issue?

The changes I made to my local copy are in framework/web/services/CWebService.php. In renderWSDL(), right before the echo, I put the ob_clean(); and in function run(), at the beginning of the method. I obviously don’t want a hijacked copy of Yii to run my app.

I never experienced such a problem on Ubuntu 8.04/10.04 workstation distribution (different Yii versions).

Captured my WSDL. There’s an extra CRLF just before the xml. The WSDL use LF only.




0170   70 65 3a 20 74 65 78 74 2f 78 6d 6c 3b 63 68 61  pe: text/xml;cha

0180   72 73 65 74 3d 55 54 46 2d 38 0d 0a 0d 0a 3c 3f  rset=UTF-8....<?

0190   78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30  xml version="1.0

01a0   22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54 46 2d  " encoding="UTF-

01b0   38 22 3f 3e 0a 3c 64 65 66 69 6e 69 74 69 6f 6e  8"?>.<definition

01c0   73 20 78 6d 6c 6e 73 3d 22 68 74 74 70 3a 2f 2f  s xmlns="http://



/Tommy

I’m running Ubuntu 11.04 (GNU/Linux 2.6.38-10-generic x86_64) and Yii yii-1.1.8.r3324. I noticed this problem also when I am displaying a pdf. I got the error message “FPDF error: Some data has already been output, can’t send PDF file”. I put in the ob_clean(); before sending the output, and it corrects the problem.

tri (Tommy), I’m not clear what you are saying … you see the extra characters, but I think you are saying they aren’t causing parsing errors? hmmm…either way, seems perhaps you have verified the symptom, and I can perhaps investigate more what is is about the parsing that is causing the problem, but generally, I understand the spec says such extra whitespace is in fact not allowed. So best to understand the cause.

Thanks for your reply!

One more thing just came to my mind: did you disable web logging?

/Tommy

I am not logging to the web page. Interestingly this same config works on the goDaddy hosted server, which led me to believe it was something with the fact I’m running on Ubuntu, or some other aspect of the hardware/OS combination. In Googling the symptom, I see that this can be caused by an extra space or newline in a php file, like this example shows: http: //stackoverflow.com/questions/3530183/fatal-error-using-fpdfsome-data-has-already-been-output-cant-send-pdf-file. (Forum won’t let a newbie like me embed an actual link …)

I’m guessing somewhere there is such an extra space in either one of my own files, or in the yii framework.

Good news, no bug in Yii (like you thought there might be! :).

The problem was I had a local config file that is called and that file had a closing ?> and a newline after it. I troubleshot this by adding the ob_clean(); right at the entry to the app in index.php. At first the system still failed when done as the first thing, because the output buffer was written to later on. So I kept moving the ob_clean() statement deeper into the code to narrow down the file that caused the problem, which led me to this particular file. Given its a local config, it’s the ONE file not deployed by my build process, and thus that was the difference between my original system and my new install.

To be safe, I understand in PHP one shouldn’t actually use a closing ?>, and so I removed that, as well as the extra newlines, and problem solved. Phew! Thanks for the replies Tommy. Go Yii.

Bad joke :huh:

I didn’t, and I don’t think you should suggest that. My comments to the captured data was for your information only. Forgive me for not being prepared to spend hours trying to assess the validity of your alleged Yii bug.

BTW You should have searched the forum before posting questions, let alone suggesting there’s a bug in the framework core. The benefit of omitted PHP closing tags has been discussed a number of times, and I posted a related answer just a couple of days ago.

/Tommy

Thanks again for your input. I am SO greatful for the support you and the community puts in to Yii. I am increasing my experience not only with Yii and PHP, but also with proper etiquette on the forum. I did search, but either missed the timing, or didn’t know my problem, thus missed the post you referenced.

Humbly,

John