[Solar-talk] Solar_Http_Response and check-headers-sent

Antti Holvikari anttih at gmail.com
Fri Jun 1 09:50:15 PDT 2007


On 6/1/07, Paul M Jones <pmjones at ciaweb.net> wrote:
> Hey Antti:
>
> Regarding the report at <http://solarphp.com/trac/ticket/74> --
>
> >  I'm Using Solar_http_*Request* in console (think webservices or
> > something
> >  like that) which returns a Solar_Http_Response when I do a fetch
> > (). If I
> >  echo something to the screen *before* I do the fetch() (which
> > tries to
> >  setHeader() for the *response* when it gets a response) I get a
> >  ERR_HEADERS_SENT error. This is because S_H_Response uses
> > headers_sent()
> >  internally, which should have nothing to do with my console script.
> >  Obviously a check to headers_sent() is needed by Solar when sending a
> >  normal response back to browser (normal use).
> >
> >  One solution would be to check for headers_sent() only when sending a
> >  response to a browser and otherwise just always allow setHeader().
> > Maybe
> >  add a Solar_Response class for Solar internal use (like
> > Solar_Request).
>
> Let me make sure I understand:  You're working at the command line,
> and you're going to echo the Solar_Http_Response to the command line,
> so of course the headers aren't going to be part of the output
> (wouldn't make sense).
>
> If that's correct, then it would make sense for Request and Response
> to be aware that you're at the CLI and not check headers_sent() in
> that case.
>
> Would that help?

Nope :(.

It has nothing to do with CLI per se. It can be a normal php_mod
request too but usually we don't echo anything *before* we make a
request with S_H_R. ok, here's an example:

// echo *before* we get a new response
echo "I send the headers.";

$req = Solar::factory('Solar_Http_Request');

// ...set uris and stuff for request object...

// this will create a response object and try to set
// headers which will fail because of the first echo
$res = $req->fetch();

hope this helps...

-- 
Antti Holvikari <http://phphalo.com>


More information about the solar-talk mailing list