You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yii1.1.22+AWS PHP v3调用S3上传时php.php文件缺失错误求助

Fixing "include(php.php): failed to open stream" Error with Yii 1.1.22 + AWS PHP SDK v3

Hey there, let's break down what's causing this frustrating error and walk through how to fix it step by step:

What's Going On Here?

This error stems from a conflict between Yii 1.1's outdated autoload mechanism and the AWS SDK v3 (which relies on Guzzle). Here's the chain of events:

  1. When Guzzle's Promise code calls method_exists() (seen in your stack trace at Promise.php:151), invalid S3 parameters or internal SDK errors trigger PHP's default autoloader.
  2. Yii 1.1's YiiBase::autoload() tries to load any class without a namespace—including a misparsed class name like php—leading to the failed attempt to find php.php.

On top of that, your upload code has a couple of obvious issues that are probably triggering the initial SDK error that cascades into this autoload mess.

Step-by-Step Fixes

1. Fix Your S3 Upload Code First

Your putObject call is missing critical required parameters, which is almost certainly causing the SDK to throw an error that leads to the autoload conflict:

$result = $s3->putObject([
    'Bucket' => 'your-actual-bucket-name', // Replace this with your real S3 bucket name (cannot be empty!)
    'Key' => 'ogo_1070.png', // Removed the trailing space here—spaces in keys can cause unexpected issues
    'Body' => fopen('/path/to/your/local/image.png', 'rb'), // You forgot this! This is the actual file content to upload
]);
  • The Bucket field is mandatory for all S3 object operations and can't be empty.
  • The Body parameter specifies the file content you want to upload—this was missing entirely in your original code.

2. Tweak Yii 1.1's Autoloader to Stop Interfering

Yii 1.1's default autoloader is too greedy—it tries to load every non-namespaced class, including those from third-party libraries like Guzzle. Let's limit it to only load Yii's own classes (core classes start with C, extensions with E):

Open framework/YiiBase.php and modify the autoload method like this:

public static function autoload($className)
{
    // Only handle Yii's own classes (C=core framework, E=extensions)
    if (!preg_match('/^[CE]/', $className) && strpos($className,'\\')===false) {
        return; // Let Composer handle all other non-namespaced classes
    }

    // Leave the original Yii autoload logic below intact
    if(isset(self::$classMap[$className]))
        include(self::$classMap[$className]);
    elseif(strpos($className,'\\')===false) // class without namespace
    {
        $className=str_replace('_','/',$className);
        if(self::$includePath===null)
        {
            if(is_file($fileName=self::getFrameworkPath().'/'.$className.'.php'))
                include($fileName);
            elseif(is_file($fileName=self::getApplicationPath().'/protected/'.$className.'.php'))
                include($fileName);
        }
        else
        {
            $fileName=self::$includePath.'/'.$className.'.php';
            if(is_file($fileName))
                include($fileName);
        }
    }
}

This change ensures Yii's autoloader stays out of the way of the AWS SDK and Guzzle's own autoloading system.

3. Verify AWS SDK Installation & Configuration

  • If you used Composer to install the AWS SDK, run composer install to make sure all dependencies (like Guzzle) are fully installed and up to date.
  • Double-check your S3 config: ensure the region matches your bucket's region, and add credentials if you're testing locally (you can skip this if your app runs on AWS with an IAM role):
$arrS3Config = [
    'region' => (getenv('APPLICATION_ENV') == 'dr') ? 'eu-central-1' : 'us-east-1',
    'version' => '2006-03-01',
    // Uncomment this block for local testing:
    // 'credentials' => [
    //     'key' => 'your-aws-access-key-id',
    //     'secret' => 'your-aws-secret-access-key',
    // ],
];

Test It Out

After making these changes, try your upload code again. The php.php error should disappear, and your file should upload to S3 as expected.

内容的提问来源于stack exchange,提问作者Osama Jetawe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 20:44:04