PHP require 'guzzle.phar' throws Fatal Error but on page refresh works

Viewed 396

I want to use Guzzle in my project without using Composer(limitation I can't avoid). I have downloaded their phar file in my project directory PROJECT_ROOT/includes/guzzle.phar

Now in my other files if I use require_once or include or include_once it throws Fatal Error below:

PHP Fatal error:  
require(): Failed opening required 'phar://guzzle.phar/autoloader.php (include_path='.:/usr/share/php:PROJECT_ROOT/includes') in PROJECT_ROOT/includes/guzzle.phar on line 3

But when I use

require 'includes/guzzle.phar'  

it throws the above error first time the page loads but when I refresh it doesn't throw any error and works ok after that.

Over the past two days, I have looked at various SO questions, tried using include_once, include, require_once and adding PROJECT_ROOT to include path but nothing seems to work.

Any help is appreciated and do let me know if any more info is needed. Thanks

1 Answers

The mentioned PHP Fatal error will throw only if the file path is in correct, you can also find Warnings mentioning the file path is incorrect just before the Fatal error.

PHP Fatal error:  
require(): Failed opening required 'phar://guzzle.phar/autoloader.php (include_path='.:/usr/share/php:PROJECT_ROOT/includes') in PROJECT_ROOT/includes/guzzle.phar on line 

On each Error/Warning/Notice PHP include information about the error cause to help the developer to track the issue.

Failed opening required 'phar://guzzle.phar/autoloader.php

From the above line/code you can find that the guzzle.phar file path is incorrect, try to use an absolute path insted of relative one.

require_once $_SERVER['DOCUMENT_ROOT'].""."includes/guzzle.phar"

Related