-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathphpEnv.js
More file actions
33 lines (28 loc) · 1.05 KB
/
phpEnv.js
File metadata and controls
33 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { execFile } from 'child_process';
import { promisify } from 'util';
import { prepareBinary } from './binHelper.js';
const execFileAsync = promisify(execFile);
export let isPhpAvailable = false;
export const checkPhpAvailable = async () => {
let phpPath = process.env.PHP_PATH || 'php';
// Check existence and permissions
const validPath = prepareBinary(phpPath);
if (!validPath) {
console.warn(`⚠️ PHP binary not found or invalid: ${phpPath}`);
isPhpAvailable = false;
return false;
}
phpPath = validPath;
try {
console.log(`[phpEnv] Verifying PHP executable: ${phpPath}`);
await execFileAsync(phpPath, ['-v']);
isPhpAvailable = true;
console.log(`✅ PHP environment check passed (${phpPath}).`);
} catch (e) {
isPhpAvailable = false;
console.warn(`⚠️ PHP environment check failed. PHP features will be disabled.`);
console.warn(`[phpEnv] Error details:`, e.message);
// console.error(e);
}
return isPhpAvailable;
};