Return to Snippet

Revision: 18095
at September 22, 2009 21:04 by renatoelias


Updated Code
< ?
// system('/Applications/Darwine/Wine.bundle/Contents/bin/wine cgi-proxy.exe');

function decode($to,$encode = false) {
$arrayobject = new ArrayObject($to);
$iterator = $arrayobject->getIterator();
while($iterator->valid()){
if ($encode)
$keywords .= $iterator->key()."=".base64_encode($iterator->current())."&";
else
$keywords .= $iterator->key()."=".$iterator->current()."&";

$iterator->next();
}
return $keywords;
}

$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", "/Users/gards/KitWvbv200/componentes_vbv/error-output.txt", "a") // stderr is a file to write to
);

$get = decode($_GET);
$post = decode($_POST);

$cwd = '/Users/gards/KitWvbv200/componentes_vbv';
$env = array('QUERY_STRING' => $get, 'REQUEST_METHOD' => 'GET');
//

$process = proc_open('/Applications/Darwine/Wine.bundle/Contents/bin/wine cgi-proxy.exe', $descriptorspec, $pipes, $cwd, $env);

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], $post);
fclose($pipes[0]);

header('Content-Type:text/html;charset=ISO-8859-1');
echo str_replace('Content-Type:text/html;charset=ISO-8859-1','',stream_get_contents($pipes[1]));
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";
}

?>

Revision: 18094
at September 22, 2009 20:59 by renatoelias


Initial Code
//	system('/Applications/Darwine/Wine.bundle/Contents/bin/wine  cgi-proxy.exe');

function decode($to,$encode = false) {
	$arrayobject = new ArrayObject($to);
	$iterator = $arrayobject->getIterator();
	while($iterator->valid()){
			if ($encode)
		        $keywords .= $iterator->key()."=".base64_encode($iterator->current())."&";
			else
		        $keywords .= $iterator->key()."=".$iterator->current()."&";
			
	        $iterator->next();
	}
	return $keywords;
}

$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", "/Users/gards/KitWvbv200/componentes_vbv/error-output.txt", "a") // stderr is a file to write to
);

$get = decode($_GET);
$post = decode($_POST);

$cwd = '/Users/gards/KitWvbv200/componentes_vbv';
$env = array('QUERY_STRING' => $get,'CONTENT_LENGTH' => strlen($post),'REQUEST_METHOD' => 'POST');
//


$process = proc_open('/Applications/Darwine/Wine.bundle/Contents/bin/wine  mpg.exe', $descriptorspec, $pipes, $cwd, $env);

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], $post);
    error_log($post."\n", 3, "mpg.log");
    fclose($pipes[0]);
	
	header('Content-Type:text/html;charset=ISO-8859-1');
    echo str_replace('Content-Type:text/html;charset=ISO-8859-1','',stream_get_contents($pipes[1]));
    error_log(stream_get_contents($pipes[1])."\n", 3, "mpg.log");
    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";
}

Initial URL
http://renatoelias.art.br/blog/2009/09/22/php-wrapper-cgi-usando-phpwine-para-rodar-cgi/

Initial Description
This a simple wrapper  for cgi, write in php, use stdin for post, and query_string env, for get

=)

Initial Title
PHP WRAPPER CGI

Initial Tags
php

Initial Language
PHP