Jump to content

Headers already sent on CLI ?


NorbertH
 Share

Recommended Posts

Hi all ,

I get a "Headers already sent" when i call PW from the commandline. If i start output before including PW.
I know that is an Issue if doing output in a webbrowser before starting the actual session but i did not expect this in a CLI call.

Here is the script: 

<?php  namespace ProcessWire;

$path = "../../index.php";
$path = realpath($path);

echo ("\nPath: " .$path. "\n");
include $path;

Here is the Error:

Path: /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/index.php
PHP Warning:  session_set_save_handler(): Cannot change save handler when headers already sent in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/WireSessionHandler.php on line 57

Warning: session_set_save_handler(): Cannot change save handler when headers already sent in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/WireSessionHandler.php on line 57
PHP Warning:  session_name(): Cannot change session name when headers already sent in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 286

Warning: session_name(): Cannot change session name when headers already sent in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 286
PHP Warning:  ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 289

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 289
PHP Warning:  ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 290

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 290
PHP Warning:  ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 291

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 291
PHP Warning:  ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 292

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 292
PHP Warning:  ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 304

Warning: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time in /usr/local/www/apache24/noexec/mein-kaffe.de/processwire/wire/core/Session.php on line 304


I am not sure but shouldn't the session be started when running from CLI ?


 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

I had a look and only thing I found is to add a $config->sessionAllow = false; in site/config.php. So this is not usable since it will disable sessions for the web site too.

Why not just including PW API at start of your main script?

EDIT:

@Ivan Gretsky Or you create a new include file (copy of index.php), like index-cli.php, to disallow sessions:

<?php namespace ProcessWire;

if (!defined("PROCESSWIRE")) define("PROCESSWIRE", 300); // index version
$rootPath = __DIR__;
if (DIRECTORY_SEPARATOR != '/') $rootPath = str_replace(DIRECTORY_SEPARATOR, '/', $rootPath);
$composerAutoloader = $rootPath . '/vendor/autoload.php'; // composer autoloader
if (file_exists($composerAutoloader)) require_once($composerAutoloader);
if (!class_exists("ProcessWire\\ProcessWire", false)) require_once("$rootPath/wire/core/ProcessWire.php");
$config = ProcessWire::buildConfig($rootPath);

$config->sessionAllow = false; // DISALLOWING SESSIONS <==============

// Rest of file...

 

Edited by da²
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...