wp插入附件太慢

icnyk63a  于 2021-06-19  发布在  Mysql
关注(0)|答案(1)|浏览(245)

我有12000个职位,我需要为他们生成缩略图。图像已在“上载”文件夹中。问题是,即使这样,过程也非常缓慢。此函数花费的时间太长。我能做些什么来加快速度吗?

function Generate_Featured_Image( $code_url, $post_id, $video_id){
        $upload_dir = wp_upload_dir();

        $path = $upload_dir['basedir'] . "/save/{$video_id}/"; 

        for($i = 6; $i >= 1; $i-- ){

            $filename = $i.'.jpg';

            if(wp_mkdir_p($path))     $file = $upload_dir['basedir'] . "/save/{$video_id}/" . $filename;

        } 

        $wp_filetype = wp_check_filetype($filename, null );
        $attachment = array(
            'post_mime_type' => $wp_filetype['type'],
            'post_title' => sanitize_file_name($filename),
            'post_content' => '',
            'post_status' => 'inherit'
            );
        $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
        require_once(ABSPATH . 'wp-admin/includes/image.php');
        $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
        $res1= wp_update_attachment_metadata( $attach_id, $attach_data );
        $res2= set_post_thumbnail( $post_id, $attach_id );
    }
b91juud3

b91juud31#

你有缓存插件和延迟加载插件吗?如果你安装jetpack(它是免费的),你将有一个免费的cdn。所以要点是:1-如果没有安装缓存插件2-如果没有安装延迟加载3-如果没有安装jetpack(它是免费的)有免费的cdn
cdn加速了站点

相关问题