Search code examples
pthreadsserverdocument-root

Pthreads doesnt know $_SERVER['DOCUMENT_ROOT']


Please i rly need help. Im calling multiple functions with pthreads .. everything works fine but i need include file in that functions and it doesnt work because $_SERVER['DOCUMENT_ROOT'] is empty in Thread.


Solution

  • You can use the following anywhere in a script file to figure out your base path:

    realpath(dirname(__FILE__))
    

    Example: put this in /srv/www/domain.com/app/config.php will output:

    /srv/www/domain.com/app
    

    Make sure to use 'DIRECTORY_SEPARATOR' to add directory slashes:

    realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR