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’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.
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.
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.
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.