• I’m running WordPress 4.9.5 multisite (subdirectory) with WordPress Importer 0.6.4, with PHP 7.0.28, wp-config has:

    define(‘FS_METHOD’, ‘direct’);

    I’m attempting to import media from another site within the same multisite instance and it fails on each attachment with the following error: “Remote file is incorrect size”.

    I’ve done hours of debugging with this and it seems to be a PHP file stat cache issue. I’ve modified the fetch_remote_file function to log the $filesize (line 1014) and it’s reporting 0 bytes. This is incorrect, however, because if I copy the $upload[‘file’] and look at the file stats via ssh it shows the exact same size as $headers[‘content-length’]. I believe what’s happening is that wp_upload_bits (on line 987) creates a temporary file that is 0 bytes and then wp_safe_remote_get (on line 992) writes the file stream to the temporary file but the filesize call (on line 1014) gets a cached filesize of 0 bytes. Under this premise I’m not sure why this ever works properly, so I’m wondering if it’s something with our PHP config or wp-config.

    Regardless, adding the following code on line 997 fixes the problem:

    clearstatcache(true, $upload['file']);

    Alternatively, adding the following hook/function to a plugin or theme functions.php fixes the problem as well:

    
    function my_http_api_debug($response, $context, $class, $r, $url) {
    	if (isset($r['filename'])) {
    		clearstatcache(true, $r['filename']);
    	}
    }
    add_action('http_api_debug', 'my_http_api_debug', 10, 5);
    

    Is there any way the clearstatcache call could be added directly to the plugin? Or do you have any insight as to why this is happening?

    Thanks!

    • This topic was modified 6 years, 6 months ago by John Russell. Reason: fixed code example
  • The topic ‘Remote file is incorrect size’ is closed to new replies.