This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » legacy support » symfony 1.0 » Strange return sfView::NONE behaviour
Strange return sfView::NONE behaviour [message #94434] Sun, 28 February 2010 17:31 Go to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
I have a strange problem.

In my application I have a few actions that is used to display an image, either from a file or by using php software to generate graphs.

All actions do the logic and then return sfView::NONE; This work for all except for one. This action do it's job but it also generate the following error in the apaches error_log file:

[Sun Feb 28 10:50:37 2010] [error] [client 192.168.5.33] PHP Warning:  Cannot modify header information -
headers already sent by (output started at /web/bit/bit_dev/plugins/dwJpgraphPlugin/lib/jpgraph/jpgraph.php:6734)
in /usr/local/lib/php/symfony/response/sfWebResponse.class.php on line 264, referer: http://bitdev.dahl-stamnes.net/bit_dev.php/trail/spongdalryespongdal/show


If I add a 'die();' before the return statement, no error.

How can this be explained?
Any suggestions how to fix this?

Thanx.


May the source be with you
Re: Strange return sfView::NONE behaviour [message #94451 is a reply to message #94434 ] Sun, 28 February 2010 22:48 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
This is nothing to do with the return value of the action AFAIK - in your library file, at line 6734, some output has been sent to the browser before symfony has had a chance to output the headers it wanted to set. Accordingly when it finally tries, it finds it is too late to send headers and so PHP issues this warning.

Track down what is on this line number and prevent it from sending any output. It might just be some whitespace after a closing php tag - in which case the closing php tag can just be removed - in raw code files it is good practise to leave them unclosed precisely for this reason.


Remember Palestine
Re: Strange return sfView::NONE behaviour [message #94463 is a reply to message #94451 ] Mon, 01 March 2010 08:23 Go to previous messageGo to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
Yes - I know. That is the image that is being sent to the client. The dwJpgraphPlugin handles the header and the image.

This work perfectly in other actions (I got 5-6 other actions using the dwJpgraphPlugin in the same way), so why should it not work in this action?

If I prevent the output at this line, I will never get any output at all (no graphs).

I'm also doing the same when showing pictures, like this:
public function executeShowImage()
{
  ... code deleted...
  $this->getResponse()->setHttpHeader('Content-type', $image->getMimeType());
  $this->getResponse()->setHttpHeader('Content-Length', $size);
  $this->getResponse()->setContent(file_get_contents($path));

  return sfView::NONE;
}


If this isn't the right way of doing it, the code above should also generate the same error, right?

[Updated on: Mon, 01 March 2010 08:23]


May the source be with you
Re: Strange return sfView::NONE behaviour [message #94465 is a reply to message #94463 ] Mon, 01 March 2010 09:06 Go to previous messageGo to next message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
Forget the code in the previous code...

I have checked a bit more in the symfony core, and it seems like symfony does not support packages/libraries as jpGraph, where the code itself output header and images in the way jpGraph do.

The only solution is to just die after the call to jpGraph (or accept the error in the error_log file).

I wonder if this "lack of support" is present in version 2.0 too? If yes, they should look at this and define a new return code in sfView that indicate that also the header has been sent and that the symfony core code does not need to send it.


May the source be with you
Re: Strange return sfView::NONE behaviour [message #94500 is a reply to message #94434 ] Mon, 01 March 2010 18:13 Go to previous messageGo to next message
halfer  is currently offline halfer
Messages: 9535
Registered: January 2006
Location: West Midlands, UK
Faithful Member
Yes, I didn't understand your previous code. Presumably you would set your headers in your action, then call your library, then return sfView::NONE? [Edit: ah, you did output the content, with setContent - missed that!]

If you start your output in dwJpgraphPlugin, and you only *sometimes* get a 'headers already sent' error, then there may be a problem with the library.

That said, try this. Set your headers in your action, followed by the call to dwJpgraphPlugin, then throw a sfStopException, and see if that sorts it. I believe this is how symfony stops things internally while providing the internals a way to clear up after itself.

If that doesn't work, can you get the image data from the library into a string? If so, then passing it from the action to the template would be trivial, and the problem would be solved.

[Updated on: Mon, 01 March 2010 18:14]


Remember Palestine
Re: Strange return sfView::NONE behaviour [message #96457 is a reply to message #94500 ] Tue, 30 March 2010 20:57 Go to previous message
skywalker  is currently offline skywalker
Messages: 334
Registered: March 2008
Location: Norway
Faithful Member
My mistake was to do was the instruction for the plugin said.

I found out that it was possible to have the plugin to generate a file instead. After the file has been generated and the plugin has completed its job, I used the code shown in this thread to output the graph. It works fine.


May the source be with you
Previous Topic:logs and purging possible bug?
Next Topic:Save the array alue
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software