Why does aws.phar work once and then fail to load again?

I install aws sdk for php in an application with elastic beanstalk using a phar file,

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

when I run the script for the first time, it succeeds! 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?

+8
php amazon-web-services elastic-beanstalk phar aws-php-sdk
source share
5 answers

Do not use require_once . This is causing this problem. You must use require or include

+5
source share

It seems that an error in some versions of the aws.phar file causes this behavior and a warning message.

Warning: require (phar: //aws.phar/aws-autoloader.php): could not open the stream: phar error: invalid url or nonexistent phar "phar: //aws.phar/aws-autoloader. Php" in / var / app / current / src / utils / AWS -SDK / aws.phar on line 3 Fatal error: require (): Could not open the required 'phar: //aws.phar/aws-autoloader.php' (include_path = '. : / Usr / share / pear: / usr / share / php)

I experimented with the same problem 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 awszip version for the AWS SDK for PHP and use 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 report success using version 2.4.9 of AWS (aws.phar), but this is too old for my purposes.

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

+1
source share

To solve the problem, I installed sdk using composer! By the way, this is the recommended technique!

0
source share

Try disabling opcache

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

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

0
source share

Make sure you specify all the namespace usage at the top of the file before executing the β€œquery”. If you include files first, it can ruin the namespace. This fixed the problem for me.

0
source share

All Articles