Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PhpSubprocess.php

function PhpSubprocess::writeTmpIni

1 call to PhpSubprocess::writeTmpIni()
PhpSubprocess::__construct in vendor/symfony/process/PhpSubprocess.php

File

vendor/symfony/process/PhpSubprocess.php, line 90

Class

PhpSubprocess
PhpSubprocess runs a PHP command as a subprocess while keeping the original php.ini settings.

Namespace

Symfony\Component\Process

Code

private function writeTmpIni(array $iniFiles, string $tmpDir) : string {
    if (false === ($tmpfile = @tempnam($tmpDir, ''))) {
        throw new RuntimeException('Unable to create temporary ini file.');
    }
    // $iniFiles has at least one item and it may be empty
    if ('' === $iniFiles[0]) {
        array_shift($iniFiles);
    }
    $content = '';
    foreach ($iniFiles as $file) {
        // Check for inaccessible ini files
        if (($data = @file_get_contents($file)) === false) {
            throw new RuntimeException('Unable to read ini: ' . $file);
        }
        // Check and remove directives after HOST and PATH sections
        if (preg_match('/^\\s*\\[(?:PATH|HOST)\\s*=/mi', $data, $matches, \PREG_OFFSET_CAPTURE)) {
            $data = substr($data, 0, $matches[0][1]);
        }
        $content .= $data . "\n";
    }
    // Merge loaded settings into our ini content, if it is valid
    $config = parse_ini_string($content);
    $loaded = ini_get_all(null, false);
    if (false === $config || false === $loaded) {
        throw new RuntimeException('Unable to parse ini data.');
    }
    $content .= $this->mergeLoadedConfig($loaded, $config);
    // Work-around for https://bugs.php.net/bug.php?id=75932
    $content .= "opcache.enable_cli=0\n";
    if (false === @file_put_contents($tmpfile, $content)) {
        throw new RuntimeException('Unable to write temporary ini file.');
    }
    return $tmpfile;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal