Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatfree framework : Call to undefined function headers_sent() #88

Open
abda11ah opened this issue Dec 9, 2024 · 3 comments
Open

Fatfree framework : Call to undefined function headers_sent() #88

abda11ah opened this issue Dec 9, 2024 · 3 comments

Comments

@abda11ah
Copy link

abda11ah commented Dec 9, 2024

Hi,

I tried to adapt Fatfree framework without success :

Here is my custom php ini :

https://github.com/joanhey/AdapterMan/blob/master/cli-php.ini

launched with php -c cli-php.ini index.php start

Here is my modified index.php :

use Adapterman\Adapterman;
use Workerman\Worker;

// Initialize F3
$f3 = Base::instance();

$f3->route('GET /',
    function() {
        echo 'Hello, world!';
    }
);

// Wrap the F3 application in a function that can be called for each request
function run() {
    global $f3;
    
    // Reset F3 for each request
    $f3->reset();
    
    // Capture the output
    ob_start();
    $f3->run();
    $response = ob_get_clean();
    
    // Return the response
    return $response;
}

// AdapterMan and Workerman setup
Adapterman::init();

$http_worker = new Worker('http://0.0.0.0:8080');
$http_worker->count = 8;
$http_worker->name = 'AdapterMan';

$http_worker->onWorkerStart = static function () {
    // Any initialization code can go here if needed
};

$http_worker->onMessage = static function ($connection, $request) {
    $connection->send(run());
};

// Only run Worker if this script is called directly (not included)
if (php_sapi_name() === 'cli') {
    Worker::runAll();
}

// Modified by Perplexity AI

error : Call to undefined function headers_sent() [/usr/src/myapp/vendor/bcosca/fatfree-core/base.php:2568]

But disabling function headers_sent() is a requirement ....

@joanhey
Copy link
Owner

joanhey commented Dec 16, 2024

Read #87 (comment)

@joanhey
Copy link
Owner

joanhey commented Dec 16, 2024

About the headers_sent() problem is that it isn't loaded the Adapterman functions before you use the FatFree framework.

You need to place the Adapterman::init() at the beginning of the file to load the functions.

EDIT: Also I think that is better to add all the Workerman and Adapterman at the beginning of the file and later the code for the framework (or in another file).
Check the recipes for others frameworks: https://github.com/joanhey/AdapterMan/tree/master/recipes

PD: we also send a PR to php-src, than when it's merged we don't need any more disable the php functions, Adapterman will be using the original php functions. php/php-src#16145
I'll start a discussion in PHP internals.

@joanhey
Copy link
Owner

joanhey commented Dec 16, 2024

I can send you an example that I use to test FatFree, but it's failing.
This christmas I'll try to to test it again, and fix the problem or send an issue to FatFree.

Actually:

fat-free-workerman: Adapterman v0.6.1 OK
fat-free-workerman: Workerman[server.php] start in DEBUG mode
fat-free-workerman: ------------------------------------------- WORKERMAN -------------------------------------------
fat-free-workerman: Workerman version:4.2.1          PHP version:8.3.14           Event-Loop:\Workerman\Events\Event
fat-free-workerman: -------------------------------------------- WORKERS --------------------------------------------
fat-free-workerman: proto   user            worker          listen                 processes    status           
fat-free-workerman: tcp     root            AdapterMan      http://0.0.0.0:8080    32            [OK]            
fat-free-workerman: -------------------------------------------------------------------------------------------------
fat-free-workerman: Press Ctrl+C to stop. Start success.
fat-free-workerman: Undefined array key "DOCUMENT_ROOT"
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] 
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] Base->{closure}()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1375] Base->trace()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1829] Base->error()
fat-free-workerman: [fat-freeindex.php:228] Base->run()
fat-free-workerman: [fat-freeserver.php:20] run()
fat-free-workerman: [fat-freevendorworkermanworkermanConnectionTcpConnection.php:653] {closure}()
fat-free-workerman: [fat-freevendorworkermanworkermanEventsEvent.php:193] EventBase->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1719] Workerman\Events\Event->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1510] Workerman\Worker::forkOneWorkerForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1484] Workerman\Worker::forkWorkersForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:561] Workerman\Worker::forkWorkers()
fat-free-workerman: [fat-freeserver.php:23] Workerman\Worker::runAll()
fat-free-workerman: Worker[34] process terminated
fat-free-workerman: 500: Undefined array key "DOCUMENT_ROOT"
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] 
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] Base->{closure}()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1375] Base->trace()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1829] Base->error()
fat-free-workerman: [fat-freeindex.php:228] Base->run()
fat-free-workerman: [fat-freeserver.php:20] run()
fat-free-workerman: [fat-freevendorworkermanworkermanConnectionTcpConnection.php:653] {closure}()
fat-free-workerman: [fat-freevendorworkermanworkermanEventsEvent.php:193] EventBase->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1719] Workerman\Events\Event->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1510] Workerman\Worker::forkOneWorkerForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1484] Workerman\Worker::forkWorkersForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:561] Workerman\Worker::forkWorkers()
fat-free-workerman: [fat-freeserver.php:23] Workerman\Worker::runAll()
fat-free-workerman: worker[AdapterMan:34] exit with status 256
fat-free-workerman: Undefined array key "DOCUMENT_ROOT"
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] 
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] Base->{closure}()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1375] Base->trace()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1829] Base->error()
fat-free-workerman: [fat-freeindex.php:228] Base->run()
fat-free-workerman: [fat-freeserver.php:20] run()
fat-free-workerman: [fat-freevendorworkermanworkermanConnectionTcpConnection.php:653] {closure}()
fat-free-workerman: [fat-freevendorworkermanworkermanEventsEvent.php:193] EventBase->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1719] Workerman\Events\Event->loop()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1510] Workerman\Worker::forkOneWorkerForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:1484] Workerman\Worker::forkWorkersForLinux()
fat-free-workerman: [fat-freevendorworkermanworkermanWorker.php:561] Workerman\Worker::forkWorkers()
fat-free-workerman: [fat-freeserver.php:23] Workerman\Worker::runAll()
fat-free-workerman: Worker[33] process terminated
fat-free-workerman: 500: Undefined array key "DOCUMENT_ROOT"
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] 
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1351] Base->{closure}()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1375] Base->trace()
fat-free-workerman: [fat-freevendorbcoscafatfree-corebase.php:1829] Base->error()
fat-free-workerman: [fat-freeindex.php:228] Base->run()
fat-free-workerman: [fat-freeserver.php:20] run()

I'll try to fix this DOCUMENT_ROOT !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants