Php 正在停止执行,错误为500
我正在编写一个小脚本,它可以调整我在WC商店中的一些特色图片的大小,它可以正常工作,但我有一个小问题 当我试图让它做多个产品(20+)时,它会阻塞并抛出一个错误500 代码本身就应该说明问题,但基本上它只需要检查所有当前产品的高度和宽度,如果不同,它会将最低值调整为最高值Php 正在停止执行,错误为500,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我正在编写一个小脚本,它可以调整我在WC商店中的一些特色图片的大小,它可以正常工作,但我有一个小问题 当我试图让它做多个产品(20+)时,它会阻塞并抛出一个错误500 代码本身就应该说明问题,但基本上它只需要检查所有当前产品的高度和宽度,如果不同,它会将最低值调整为最高值 $aWCProductARGS = array( 'post_type' => 'product', 'posts_per_page' => -1
$aWCProductARGS = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$aWCProducts = new WP_Query( $aWCProductARGS );
$response['count'] = count($aWCProducts->posts);
foreach($aWCProducts->posts as $key => $oProduct)
{
$sProductImage = wp_get_attachment_image_src( get_post_thumbnail_id($oProduct->ID), 'full' );
$sProductImageDIR = wp_upload_dir()['basedir'] . substr($sProductImage[0], strpos($sProductImage[0], "uploads")+7);
$sProductImageWidth = $sProductImage[1];
$sProductImageHeight = $sProductImage[2];
if($sProductImageWidth > $sProductImageHeight)
{
$thumb_h = $sProductImageWidth;
$thumb_w = $sProductImageWidth;
}
else
{
$thumb_h = $sProductImageHeight;
$thumb_w = $sProductImageHeight;
}
$original_info = getimagesize($sProductImageDIR);
$original_w = $original_info[0];
$original_h = $original_info[1];
$response['imageCreate'] = imagecreatefromfile($sProductImageDIR);
$original_img = imagecreatefromfile($sProductImageDIR);
$hal_big_x = $thumb_w / 2;
$hal_big_y = $thumb_h / 2;
$half_small_x = $original_w / 2;
$half_small_y = $original_h / 2;
$coord_x = $hal_big_x - $half_small_x ;
$coord_y = $hal_big_y - $half_small_y ;
$thumb_img = imagecreatetruecolor($thumb_w, $thumb_h);
if( check_if_png($sProductImageDIR) == 'png' )
{
imagesavealpha($thumb_img, true);
$trans_colour = imagecolorallocatealpha($thumb_img, 0, 0, 0, 127);
imagefill($thumb_img, 0, 0, $trans_colour);
imagealphablending($original_img, true);
imagesavealpha($original_img, TRUE);
}
else
{
$white = imagecolorallocate($thumb_img, 255, 255, 255);
imagefill($thumb_img, 0, 0, $white);
}
imagecopyresampled($thumb_img, $original_img,
$coord_x, $coord_y,
0, 0,
$original_w, $original_h,
$original_w, $original_h);
saveimagedata($thumb_img, $sProductImageDIR, $sProductImageDIR);
imagedestroy($thumb_img);
imagedestroy($original_img);
$res = get_attached_file( $oProduct->ID );
$metadata = wp_generate_attachment_metadata( $oProduct->ID, $sProductImageDIR );
wp_update_attachment_metadata( $post_id, $metadata );
}
我相信它会抛出大约20个错误(当调用imagecreatefromfile()
时)
PHP执行时间设置为500-但它在大约3-4秒后崩溃,因此这并不重要。检查apache错误日志,或者如果您处于开发阶段,则使用
ini\u set('display\u errors',1)打印错误;错误报告(E_全部)代码>检查您的apache错误日志,或者如果您处于开发阶段,则使用ini\u set('display\u errors',1)打印错误;错误报告(E_全部)代码>