Part of the EllisLab Network
   
 
Unintentional output by libraries
Posted: 08 December 2006 07:20 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  8
Joined  12-08-2006

Hello everyone,
I just had a very nasty bug. My app needs to create some charts on the fly, so i’m using http://www.zackbloom.org/ graphing library, copied to ‘application/libraries’ folder.
I was loading library as usual ($this->load->library(‘graph’)), and creating graphs correctly, but the image output was somehow corrupt. If I saved the file to server it worked fine but when I output it to browser it was corrupt. The headers sent back by server were correct but the image had some newlines before the real content. And guess what? The extra line breaks were at the end of graph.oo.php file. It took me more than hour (I’m completely new to CI as well as graph.oo.php) to find this problem.
I was thinking, that maybe you could add additional parameter to load->library() method $dropOutput, which would drop any output by this library.
I mean something like this in your library loading routine

<?php
if ($dropOutput) ob_start();
//load library as usual, include it's files and so on
if ($dropOutput) ob_end_clean();
?>


In my case it was very easy to fix it because I had only one file. But what if a library consists of tens of files? Such unintentional output doesn’t do too much harm for apps which only output text/html but as you see it can be deadly when dealing with images.

EDIT: Sorry, this might be more appropriate in Feature requests area.

 Signature 

Signature for rent. Good as new.
3 lines/80 chars max.
$0.02 per post

Profile
 
 
Posted: 09 December 2006 03:56 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  300
Joined  10-17-2006

Output in external libraries is not a mistake of CI but a mistake of the library in question. Libraries should not echo anything on loading them. I see no need for CI to fix faulty libraries and thus no need for such a feature.

Profile
 
 
Posted: 09 December 2006 10:56 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  886
Joined  03-06-2006

Why couldn’t you make a wrapper file that buffers the output, loads your library, then discards the buffer?

Basically the same as what you have in the code above, just call it and let it call the library.

I agree that CI should not try to anticipate the way any external library works.

 Signature 

Corozal, Belize | Linux.bz | Using Kubuntu Linux 7.10 | CodeIgniter 1.5.3

Profile
 
 
Posted: 09 December 2006 03:43 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Avatar
Total Posts:  8
Joined  12-08-2006

Yes, I’m aware that it’s not CI’s fault but I intially thought that it could add additional power to CI.

And one more question: when are libraries loaded if they are specified in autoload.php? When controller’s constructor is called?

 Signature 

Signature for rent. Good as new.
3 lines/80 chars max.
$0.02 per post

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66413 Total Logged-in Users: 32
Total Topics: 84753 Total Anonymous Users: 0
Total Replies: 454831 Total Guests: 232
Total Posts: 539584    
Members ( View Memberlist )
Newest Members:  byrooNirCalexmuellerkizerdrixcaptainredmuffquinodligtharttechsivamDjordjesammozza