8

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 ?

david
  • 3,310
  • 7
  • 36
  • 59

5 Answers5

5

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

Néstor
  • 570
  • 2
  • 8
  • 22
  • good point. i will try this. but How require_once effects . it shouldn't , right ? – david Aug 14 '15 at 11:33
  • No, `require_once` calls only once the file: http://php.net/manual/es/function.require-once.php. what I've noticed is that you have to make continously callings to the aws bootstrap to make it works. – Néstor Aug 14 '15 at 15:55
1

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/

jhcaiced
  • 716
  • 8
  • 11
  • 1
    Ya, I'm not sure what causes this but doing the sdk reference route fixed it for us. The weird part was that we had it running fine for months, didn't even change the .phar file, and then it broke. – CasualT Mar 20 '15 at 00:33
1

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+)

b7kich
  • 4,253
  • 3
  • 28
  • 29
  • The issue occurred for me when I moved my phar file to another location. I had to restart Apache after doing this because Apache cached its location. Simply running the apache restart command fixed the issue for me. – Freddie Nov 28 '18 at 18:20
0

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

david
  • 3,310
  • 7
  • 36
  • 59
0

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.

leiavoia
  • 533
  • 1
  • 6
  • 12