Skip to content

Instantly share code, notes, and snippets.

@philip
Created January 3, 2013 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philip/4447352 to your computer and use it in GitHub Desktop.
Save philip/4447352 to your computer and use it in GitHub Desktop.
Hack to test --enable-* and --with-* for PHP. This may or may not work, but seems to work. Proof-of-concept. :)
<?php
// TODO: Pass in --disable-all?
// Ideally, pass in all, and disable one at a time (know which caused failure), then log error, remove, try again
$enables = get_all_options('enable');
$withs = get_all_options('with');
$good = $bad = array();
foreach ($withs as $directive) {
shell_exec("make clean");
$out = shell_exec("./configure {$directive['directive']}");
if (strpos($out, "Thank you for using PHP.")) {
$good[] = $directive;
} else {
$bad[] = $directive;
}
}
print_r($good);
print_r($bad);
save_information($good, $bad);
function get_all_options($type = 'enable') {
$out = shell_exec('./configure --help');
preg_match("@Extensions:(.*)Zend:@s", $out, $matches);
if (empty($matches[1])) {
return false;
}
$out = $matches[1];
$settings = array();
foreach (explode(PHP_EOL, $out) as $k => $line) {
$line = trim($line);
if (0 !== strpos($line, '--' . $type . '-')) {
continue;
}
// TODO: Add description
$setting = preg_replace("@( |=)(.*)$@", "", $line);
$settings[] = array('directive' => $setting, 'description' => '');
}
return $settings;
}
function save_information($good, $bad) {
$data = "\n\n========== " . time() . " =========\n";
$data .= "Good\n";
foreach ($good as $g) {
$data .= "$g[directive] ";
}
$data .= "\nBad\n";
foreach ($bad as $b) {
$data .= "$b[directive] ";
}
file_put_contents("/tmp/php-config.txt", $data, FILE_APPEND);
}
function test_environment() {
// Get version info for stuff like autoconf, gcc, php-src, pwd, ...
// If --help fails, then return false
$out = shell_exec("./configure --help");
// If --disable-all fails, then likely return false
$out = shell_exec("./configure --disable-all");
// If empty configure fails, then maybe fail
$out = shell_exec("./configure");
// This will likely always fail, but would be great :)
$out = shell_exec("./configure --enable-all");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment