XF 2.1 How to disable error handling in XF2?

researcher

Member
Hi, how are you?
I have just developed a PHP script and using this in a page node with callbacks. But I get some little PHP errors like:
Cannot modify header information - headers already sent by

I entered this code: XenForo_Application::disablePhpErrorHandler();
But not working, now I am getting this error:
[B]Error[/B]: Class 'XenForo_Application' not found in [B]src/addons/SimpleAddon_index.php[/B] at line [B]28[/B]

How can I disable the error handling in XF2?

Thanks.
 
I have tried them but not worked:
ini_set('display_errors', 0);
error_reporting(0);
error_reporting(E_ALL | E_STRICT & ~8192);

Errors still get displayed.
 
I couldnt fix them. I am using ob_start(); function and so I get Cannot modify header information - headers already sent by error. Also, think that there is an empty array, while I am using count($emptyarray); I got error too... How can I fix them?
You should be fixing your code instead of suppressing them.
If you get such messages your code contains errors, fix them and the messages will be gone.
 
You need to show the entire script you're trying to run so anyone can have any idea what is wrong with the script other than you using XF1 code.
 
You need to show the entire script you're trying to run so anyone can have any idea what is wrong with the script other than you using XF1 code.
Normally, there is no issue in my codes... I get classical PHP errors. Scripts is running well but I need to disable error handling... Because I think it is not possible to fix count($emptyarray); error. Or a header sent error... There should be a way...
 
Okey, I will try. :) And I have fixed the count error as:
PHP:
if(empty($emptyarray)){
$count = 0;
}else{
$count = count($emptyarray);
}

But I could not fix this error:
Code:
An exception occurred: [ErrorException] [E_WARNING] Cannot modify header information - headers already sent by (output started at /var/www/vhosts/example.com/httpdocs/src/addons/TestCallbacks_index.php:332) in src/XF/Http/Response.php on line 386

XF::handlePhpError()
header() in src/XF/Http/Response.php at line 386
XF\Http\Response->sendHeaders() in src/XF/Http/Response.php at line 283
XF\Http\Response->send() in src/XF.php at line 440
XF::runApp() in index.php at line 20

I am using ob_start(); and ob_end_flush(); , this functions causes this error... How to solve?

If you do get errors there are issues :rolleyes:
Don't try to band-aid broken code by hiding errors, fix them!
 
It would help to post the whole file ...

If this is not possible you'd at least need to post the code in line 332 (+ some context).

I don't want to sound too harsh, but to me it seems like your PHP knowledge is ~ beginner level; IMHO properly developing for XenForo does require quite a bit more than that.
 
@Kirby my codes like this:
PHP:
<?php
if (ob_get_level() == 0) ob_start();
for ($i = 0; $i<10; $i++){

        echo "<br> Line to show.";
        echo str_pad('',4096)."\n";   

        ob_flush();
        flush();
}

ob_end_flush();

?>

Why are you trying to use ob_start/ob_end_flush ? XenForo has an entire templating system
I am using flush(); to run codes while the page is loading. Or, user will wait the loading more than 2minutes and the page will display gateway timeout error... Is there an alternative to flush() in XF?
 
How you're trying to achieve is wrong. Try doing the following:
  1. Create a controller
  2. Add action named "Index"
  3. Create a new template named "myVerySpecial_view"
  4. Return a "View" reply which uses uses the above template
Use the very minimalistic documentation found here to get started on how to create controller.
 
I cant understand them, I am not a php-pro...:rolleyes:

How you're trying to achieve is wrong. Try doing the following:
  1. Create a controller
  2. Add action named "Index"
  3. Create a new template named "myVerySpecial_view"
  4. Return a "View" reply which uses uses the above template
Use the very minimalistic documentation found here to get started on how to create controller.
 
I cant understand them, I am not a php-pro...:rolleyes:
That's the problem ;)
XenForo is professional software built on "state-of-the-art" technology (MVC, DI, etc.), beginner level PHP knowledge simply isn't enough to build upon it.

You can't use flushing (eg. creating a streaming type response) and render a XenForo HTML page as response at the same time, this won't work properly no matter how you try to bend it.

The first step would be to explain exactly what you are actually trying to do and why it does take that long.
Maybe the approach is just wrong and could be optimized or you'd need a complately different approach (job, background process, etc.).
But to give advice we need to know what you want to achieve.
 
Last edited:
I have developed a tool with PHP, it scans 300+ websites and check their source codes. with curl. It is working well, but in XenForo, I get header error. I need use flush(); to avoid timeout problem and dont force users to wait... And I have to solve this header problem... I think it is about Content-Length header. How can I solve?

That's the problem ;)
XenForo is professional software built on "state-of-the-art" technology (MVC, DI, etc.), beginner level PHP knowledge simply isn't enough to build upon it.

You can't use flushing (eg. creating a streaming type response) and render a XenForo HTML page as response at the ame time, wthis won't work properly no matter how you try to bend it.

The first step would be to explain exactly what you are actually trying to do and why it does take that long.
Maybe the approach is just wrong and could be optimized or you'd need a complately different approach (job, background process, etc.).
But to give advice we need to know what you want to achieve.
 
I think it is about Content-Length header.
No. The problem is that you are generating output before XenForo sends headers (as stated in the error message).
As said before, this simply does not work.

How can I solve?
You can't, take a different approach.
Personally, I'd probably implement this as a Job + Service and update the page via AJAX when result(s) are ready.
 
Last edited:
Back
Top Bottom