codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: i expect to see errors #7843

Closed itisjoby closed 1 year ago

itisjoby commented 1 year ago

PHP Version

8.2

CodeIgniter4 Version

4.3.2

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

Mongodb

What happened?

My 2 projects share some data with curl post. the sender project is running codeigniter 3 and receiver is running codeigniter 4.3.2. when i try to send data i am getting 500 http status code.

but there is no response of what the error was even after i ask php to display errors .

the problem is when CI_ENVIRONMENT in .env is set as production. https://prnt.sc/JzVAPYsHf4ks when it is set as development i am getting proper response. https://prnt.sc/_Xlp9cnFA5Ly

but since this is a production server and i only want to enable errors for one page i am puzzled here.

Steps to Reproduce

1.) set CI_ENVIRONMENT = production in .env file 2.) write 2 functions a) reciever.php

      function processing() {
        ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);
        dd($and);
    }

b) sending.php

    function sending() {

        try {
            $curl         = curl_init();
            $request_body = [];
            curl_setopt_array($curl, array(
                CURLOPT_URL            => "**reciever.php**",
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING       => "",
                CURLOPT_MAXREDIRS      => 10,
                CURLOPT_TIMEOUT        => 30,
                CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST  => "POST",
                CURLOPT_POSTFIELDS     => json_encode($request_body),
                CURLOPT_HTTPHEADER     => array(
                    "authorization: Bearer test",
                    "content-type: application/json"
                ),
            ));
            $response     = curl_exec($curl);
            dd("curl_exec response : ", 0);
            dd($response, 0);
            $http_status  = curl_getinfo($curl, CURLINFO_HTTP_CODE);
            $response     = json_decode($response);
            $err          = curl_error($curl);

            curl_close($curl);
            dd("http_status : ", 0);
            dd($http_status, 0);
            dd("curl_error : ", 0);
            dd($err);

        } catch (\Exception $e) {
            dd($e->getMessage(), 0);
        }
    }

3.) run sending function

Expected Output

i expect to see errors because i forcefully requested php to show errors with code .

ini_set('display_errors', 1);
        ini_set('display_startup_errors', 1);
        error_reporting(E_ALL);

Anything else?

No response

kenjis commented 1 year ago

We use GitHub issues to track BUGS and to track approved DEVELOPMENT work packages. We use our forum to provide SUPPORT and to discuss FEATURE REQUESTS.

kenjis commented 1 year ago

dd() outputs nothing in production environment. And you can see errors in log files on the server.

itisjoby commented 1 year ago

dd() outputs nothing in production environment. And you can see errors in log files on the server.

i donot use ci4 dd() this is a custom function that print data so it will work fine in production too, as you can see from the provided screenshot. my issue is not still resolved. @kenjis can i open a new issue

kenjis commented 1 year ago

No. This is not a bug.

Why don't you see the log file? It is the easiest way to see the error.

itisjoby commented 1 year ago

@kenjis i understood. i can see the error in server2 log. but i am getting 2 responses when i directly loading the receiver.php and loading it via curl. when i load it directly i get error response that there is no variable. but in curl i dont get any response. is this out of ci4 question?

kenjis commented 1 year ago

It is not a framework issue. The framework does not show errors in production environment. It is intentional.

Unfortunately, there is no easy way to show detailed errors that you want with the framework. Even if there is, the core code of the framework would need to be customized. At least I don't immediately know how to customize it.