Home » Php » php – why aws.phar runs once then won't load again?

php – why aws.phar runs once then won't load again?

Posted by: admin July 12, 2020 Leave a comment

Questions:

I install aws sdk for php in my elastic beanstalk application using phar file,:

require_once __DIR__ . '/../AWS-SDK/aws.phar';

when I run the script for the first time, it succeed ! but when I try again I got this error :

Warning: require(phar://aws.phar/aws-autoloader.php): failed to open stream: phar error: invalid url or non-existent phar "phar://aws.phar/aws-autoloader.php" in /var/app/current/src/utils/AWS-SDK/aws.phar on line 3 Fatal error: require(): Failed opening required 'phar://aws.phar/aws-autoloader.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/app/current/src/utils/AWS-SDK/aws.phar on line 3

How to solve the problem ?

How to&Answers:

Don’t use require_once. That’s causing that issue. You should use require or include

Answer:

There seems to be an error on some versions of the aws.phar file that causes this behavior and warning message.

Warning: require(phar://aws.phar/aws-autoloader.php): failed to open stream: phar error: invalid url or non-existent phar “phar://aws.phar/aws-autoloader.php” in /var/app/current/src/utils/AWS-SDK/aws.phar on line 3 Fatal error: require(): Failed opening required ‘phar://aws.phar/aws-autoloader.php’ (include_path=’.:/usr/share/pear:/usr/share/php’)

I was experimenting the same issue using aws.phar with version 2.7.17 of the AWS SDK for PHP

The solution that worked for me was to download and extract the aws.zip version of the AWS SDK for PHP and require aws-autoloader.php instead as described in the installation docs.

http://docs.aws.amazon.com/aws-sdk-php/guide/latest/installation.html#installing-via-zip

Some people reports success when using the 2.4.10 version of the AWS (aws.phar) but that is too old for my purposes.

https://pyd.io/f/topic/pydio-6-0-s3-plugin-phar-error/

Answer:

to solve the problem I’v installed the sdk using composer ! BTW it’s the recommended technique !

Answer:

Try turning off opcache

  • add the following to /etc/php5/apache2/php.ini opcache.enable=0
  • restart apache service apache2 restart

This is a know issue at least with older versions of the aws.phar and there seems to be a general issue with phars and opc (formerly Zend Optimizer+)

Answer:

Make sure you declare all namespace usage at the top of the file before you do “require”. If you include files first, it can mess up the namespacing. This fixed the issue for me.