Autor Zpráva
Zlomenina
Profil
Potrebuju pomoci PHP ovladat externi procesy - nevedel jsem, ze to PHP taky umi. Pravda lip pod linuxem - tam je nepreberne mnozstvi funkci. Windows XP podporuje snad pouze proc_open, proc_close, ...terminate,...get_status. Problem mam v nasledujicim kodo - ovsem zadna chyba neni hlasena. Jde o to, ze nadefinovane PIPES, jsou sice otevrene, muzu ke zavrit, ale kdyz do nich neco poslu, tak vysledek, je jako kdyz, hrach na stenu hazi - proste nic se nedeje. Hello World se nevypise. Ptam se proc?
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "error-output.txt", "a") // stderr is a file to write to
);
$process = proc_open("php", $descriptorspec, $pipes);
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt

fwrite($pipes[0], "<?php echo \"Hello World!\"; ?>");
fclose($pipes[0]);

while (!feof($pipes[1])) {
echo fgets($pipes[1], 1024);
}
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);

echo "command returned $return_value\n";
}
?>

Toto spoustim samozrejme z command-line : php index.php
, vysledek je tento:
command returned 0
Zlomenina
Profil
V praci mi to nefunguje, doma ano.
Zlomenina
Profil
Pokud ovsem udelam zmenu a spousteny proces udelam interaktivni :

0 => array("file", "php://stdin", "r") - presmeruju stdin na php://stdin detskeho procesu

a vypustim radky :

fwrite($pipes[0], "<?php echo \"Hello World!\"; ?>");
fclose($pipes[0]);

a pri spusteni php index.php rucne zadam (za behu - interaktivne) :

<?php echo "Hello World!"; ?>
Ctrl-Z

tak PIPES funguje a vypise se:

Hello World!command returned 0
Zlomenina
Profil
Tak problem bylv php.ini v nastaveni modulu ZEND. Nevim k cemu je tahle direktiva:

zend_extension_ts="C:\Program Files\Zend\StudioServer\lib\ZendExtensionManager.dll

,kdyz se zakomentuje, tak to slape tak jakl ma. Rad bych, ale zvedel, co to zpusobuje, k cemu to je apod.
Zlomenina
Profil
Tak si to asi nakonec vyresim sam. ZendExtensionManager.dll je externi modul ZEND, ktery umoznuje pripojeni dalsich Zend extensions. Ovsem k cemu je Zend opravdu potreba to presne nevim. Ja mam v PHP.ini pripojeny extensions Debugger a Optimizer. Velice vyhodne je zrejme pripojeni Zend Cache, ale to nemam. Nicmene problem stale zustava...proc se Hello world s modulem ZEND nevypise a bez nej naopak?
Toto téma je uzamčeno. Odpověď nelze zaslat.

0