Files
Sdf1_login/api/gh_git_probe.php
T
ypsdf1 a8ac78a87f 15m44w 续5c 根治横条消失: 删全仓 curl_close + JSON 端点抑制 deprecation 输出
真根因(推翻 token 过期说): PHP8.5 下 curl_close() 已废弃, 每次调用都输出
<br><b>Deprecated</b> 污染 JSON 响应体 → 前端 res.json() 解析失败进 catch
(端点 catch 注释'不显示') → GitHub 授权横条消失。实测 gh_cfg 后端验活 status=200
ok=true 但响应体被警告污染, 非纯 JSON。

修: ① 全仓 8 处独立 curl_close 语句删除(PHP8+ 是 no-op,  出作用域自动关闭,
   删了不改行为还消除 deprecation 源头); ② gh_cfg/gh_diag/gh_git_probe 顶部加
   error_reporting(0)+display_errors=0 兜底, 彻底防任何警告污染响应体。
实测部署后 gh_cfg.php 返回纯 JSON, gh_authorized=true。
2026-11-25 20:40:38 +08:00

76 lines
2.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 15m44w: 服务端 git 可用性 + imgrepo 仓可达性 探测端点。
* 用法:GET gh_git_probe.php (无鉴权,仅诊断;返回 git 版本 + imgrepo 配置 + 是否可访问仓)
* 用于定位"附件 git 推图仓"功能是否能在服务器跑起来(git 二进制/exec 权限/仓可达性)。
*/
while (ob_get_level() > 0) { @ob_end_clean(); }
ob_start();
// ★ 15m44w 续5c:抑制 deprecation/notice 输出,保 JSON 响应体纯净(PHP8.5)
error_reporting(0);
ini_set('display_errors', '0');
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
require_once __DIR__ . '/../core.php';
require_once __DIR__ . '/../lsky.php';
require_once __DIR__ . '/../gh_api.php';
$cfg = loadImgJson();
// 1) git 二进制是否可用
$gitOk = false;
$gitVer = '';
$gitCmd = 'git --version';
if (function_exists('exec')) {
$out = [];
$ret = 0;
@exec($gitCmd . ' 2>&1', $out, $ret);
if ($ret === 0 && !empty($out)) {
$gitOk = true;
$gitVer = trim(implode(' ', $out));
}
} elseif (function_exists('shell_exec')) {
$out = @shell_exec($gitCmd . ' 2>&1');
if (is_string($out)) { $gitVer = trim($out); $gitOk = ($gitVer !== ''); }
}
// 2) imgrepo 配置
$ir = [
'mode' => $cfg['imgrepo_mode'] ?? '',
'owner' => $cfg['imgrepo_owner'] ?? '',
'full' => $cfg['imgrepo_full'] ?? '',
'branch' => $cfg['imgrepo_branch'] ?? '',
'token' => (isset($cfg['imgrepo_token']) && $cfg['imgrepo_token'] !== '') ? substr($cfg['imgrepo_token'], 0, 4) . '****' : '',
];
// 3) 仓可达性(带 token GET raw 域名,不实际推)
$reach = '';
$reachStatus = 0;
if ($ir['full'] !== '' && $ir['owner'] !== '') {
$rawUrl = 'https://raw.githubusercontent.com/' . $ir['full'] . '/' . $ir['branch'];
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rawUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_exec($ch);
$reachStatus = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$reach = 'HTTP ' . $reachStatus;
}
}
success([
'git_available' => $gitOk,
'git_version' => $gitVer,
'exec_func' => function_exists('exec'),
'proc_open' => function_exists('proc_open'),
'imgrepo' => $ir,
'raw_reach' => $reach,
'hint' => $gitOk
? 'git 可用,附件可走 git 推图仓'
: '⚠ 服务器 git 不可用(未装 git 或 exec 被禁),附件 git 推图仓功能无法运行——需服务器装 git 并放开 PHP exec',
], 'ok');