<?php
$required=['bcmath','curl','dom','fileinfo','gd','iconv','intl','json','mbstring','openssl','pcntl','PDO','pdo_dm','redis','session','sockets','xml','zip','zlib'];$missing=[];
foreach($required as$n)if(!extension_loaded($n))$missing[]=$n;
$unicode='中文菜牌𠮷😀';$json=json_encode(['text'=>$unicode],JSON_UNESCAPED_UNICODE);
$ops=[];$tmp=null;$sid='zhctcheck'.bin2hex(random_bytes(8));
try{
 $tmp=tempnam(sys_get_temp_dir(),'zhct-check-');if($tmp===false)throw new RuntimeException('temp write denied');
 $z=new ZipArchive();if($z->open($tmp,ZipArchive::OVERWRITE)!==true)throw new RuntimeException('zip open failed');$z->addFromString('check.txt','中文ZIP');$z->close();
 if($z->open($tmp)!==true||$z->getFromName('check.txt')!=='中文ZIP')throw new RuntimeException('zip roundtrip');$z->close();$ops['zip_roundtrip']=true;
 $im=imagecreatetruecolor(4,4);ob_start();imagepng($im);$png=ob_get_clean();imagedestroy($im);if(substr($png,0,8)!=="\x89PNG\r\n\x1a\n")throw new RuntimeException('gd image invalid');$ops['gd_png']=true;
 $fi=new finfo(FILEINFO_MIME_TYPE);if($fi->buffer($png)!=='image/png')throw new RuntimeException('fileinfo mime mismatch');$ops['fileinfo_png']=true;
 session_id($sid);if(!session_start())throw new RuntimeException('session open failed');$_SESSION['check']='session中文';session_write_close();session_id($sid);if(!session_start()||($_SESSION['check']??null)!=='session中文')throw new RuntimeException('session read failed');session_destroy();$ops['session_roundtrip']=true;
}catch(Throwable$e){$ops['error']=get_class($e).': '.$e->getMessage();}finally{if($tmp!==null&&is_file($tmp))unlink($tmp);}
$pathsOk=realpath(php_ini_loaded_file())===realpath(__DIR__.'/../etc/php.ini')&&ini_get('include_path')==='.'&&strpos(ini_get('extension_dir'),'/www/server/')===false;
$ok=PHP_VERSION==='7.3.32'&&PHP_ZTS===0&&!$missing&&in_array('dm',PDO::getAvailableDrivers(),true)&&$json!==false&&json_decode($json,true)['text']===$unicode&&ini_get('date.timezone')==='Asia/Shanghai'&&count($ops)===4&&!isset($ops['error'])&&$pathsOk;
echo json_encode(['passed'=>$ok,'operations'=>$ops,'paths_isolated'=>$pathsOk,'php'=>PHP_VERSION,'nts'=>PHP_ZTS===0,'missing_modules'=>$missing,'pdo_drivers'=>PDO::getAvailableDrivers(),'unicode_json'=>$json!==false,'dm_svc_path'=>getenv('DM_SVC_PATH'),'redis_extension'=>phpversion('redis'),'zip_extension'=>phpversion('zip')],JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT),"\n";exit($ok?0:1);
