can I suppress headers in PHP/CLI?

Posted on 2009-04-20
Last Modified: 2013-11-10
I have Zend Framework-based web site. When I start application from Cron I always get this output. How can I suppress such PHP headers in Zend? Or maybe it's a global PHP option?
X-Powered-By: PHP/5.2.9

Set-Cookie: PHPSESSID=a6f12eabbe240c78b7381418b4d21ce3; path=/

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Content-type: text/html

Open in new window

Question by:technoparkcorp
    LVL 14

    Expert Comment


    try with this:

    expose_php = Off in php.ini file.
    LVL 8

    Expert Comment


    #!/usr/local/bin/php -q

    Open in new window


    Author Comment

    I tried both options, no effect :(
    LVL 3

    Expert Comment

    I think the -q option is what you need (as aldanch has written). Maybe the path is wrong for your installation?

    Try this from a shell/command prompt:

    php -q test.php

    Author Comment

    this is what I get when I use -q
    <br />
    <b>Fatal error</b>:  Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /0' in /home/xxx/library/Zend/Session.php:419
    Stack trace:
    #0 /home/xxx/application/bootstrap.php(92): Zend_Session::start()
    #1 /home/xxx/application/Robot/run.php(22): require('/home/xxx...')
    #2 {main}
      thrown in <b>/home/xxx/library/Zend/Session.php</b> on line <b>419</b><br />

    Open in new window

    LVL 3

    Accepted Solution

    I think where getting to the problem now. If you look at this page, it says that Zend_Session is (was?) not supported in the CLI environment:

    So you can either run the script within a browser with your cron script (possible but a bit clunky) or maybe try putting this just before line 92 in bootstrap.php:

    if (php_sapi_name() == 'cli') Zend_Session::$_unitTestEnabled = true;

    Or some other code using the same check that will bypass Zend_Session if the script is run in the CLI environment.

    Author Closing Comment

    It's always "cli", in my case it's "cgi-fcgi". Anyway it works now, thanks!
    LVL 3

    Expert Comment

    Thanks for the points. I assumed from your use of Zend_Session that this code must also be intended to be run in a browser.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now