Site crashes when I require a directory for my module [on hold]


I have a custom php code that lives in my_code.php file. In the begining of the file there is the line

 require __DIR__ . '/vendor/autoload.php';

The code works perfectly if I visit mysite/my_code.php but I need to be executed when a form is submited. So I placed the code in a form alter hook and the line

require __DIR__ . '/vendor/autoload.php';

in the beggining of my_custom_module.module file like this

require __DIR__ . '/vendor/autoload.php';
use DrupalnodeEntityNode;
use DrupalCoreFormFormStateInterface;
use DrupalCoreEntityEntityTypeInterface;

function my_custom_module_form_alter(&$form, $form_state, $form_id)
{ code....}

but the site crashes… Why does the code

require __DIR__ . '/vendor/autoload.php';

work in a php file but not in my module’s .module file? What am I doing wrong?

The message from my site’s logs is

mod_fcgid: stderr: PHP Fatal error: require(): Failed opening required
/autoload.php' (include_path='.:/usr/share/pear/:') in /var/www/vhosts
/ on line 2

What should I change?

قالب وردپرس