PHP包装器CGI

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP包装器CGI相关的知识,希望对你有一定的参考价值。

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

=)
  1. < ?
  2. // system('/Applications/Darwine/Wine.bundle/Contents/bin/wine cgi-proxy.exe');
  3.  
  4. function decode($to,$encode = false) {
  5. $arrayobject = new ArrayObject($to);
  6. $iterator = $arrayobject->getIterator();
  7. while($iterator->valid()){
  8. if ($encode)
  9. $keywords .= $iterator->key()."=".base64_encode($iterator->current())."&";
  10. else
  11. $keywords .= $iterator->key()."=".$iterator->current()."&";
  12.  
  13. $iterator->next();
  14. }
  15. return $keywords;
  16. }
  17.  
  18. $descriptorspec = array(
  19. 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
  20. 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
  21. 2 => array("file", "/Users/gards/KitWvbv200/componentes_vbv/error-output.txt", "a") // stderr is a file to write to
  22. );
  23.  
  24. $get = decode($_GET);
  25. $post = decode($_POST);
  26.  
  27. $cwd = '/Users/gards/KitWvbv200/componentes_vbv';
  28. $env = array('QUERY_STRING' => $get, 'REQUEST_METHOD' => 'GET');
  29. //
  30.  
  31. $process = proc_open('/Applications/Darwine/Wine.bundle/Contents/bin/wine cgi-proxy.exe', $descriptorspec, $pipes, $cwd, $env);
  32.  
  33. if (is_resource($process)) {
  34. // $pipes now looks like this:
  35. // 0 => writeable handle connected to child stdin
  36. // 1 => readable handle connected to child stdout
  37. // Any error output will be appended to /tmp/error-output.txt
  38.  
  39. // fwrite($pipes[0], $post);
  40. fclose($pipes[0]);
  41.  
  42. header('Content-Type:text/html;charset=ISO-8859-1');
  43. echo str_replace('Content-Type:text/html;charset=ISO-8859-1','',stream_get_contents($pipes[1]));
  44. fclose($pipes[1]);
  45.  
  46. // It is important that you close any pipes before calling
  47. // proc_close in order to avoid a deadlock
  48. $return_value = proc_close($process);
  49.  
  50. //echo "command returned $return_value ";
  51. }
  52.  
  53. ?>

以上是关于PHP包装器CGI的主要内容,如果未能解决你的问题,请参考以下文章

Perl CGI 日期和时间选择器,自动填充当前日期和时间

swig-php 包装器使用指针,c 代码是一个数组

FragmentContainer 与仅作为包装器的另一个 React 组件?

tesseract-php 包装器在本地主机上运行时出现路径错误

CGI,FastCGI和PHP-FPM之间的关系和区别

在Visual Studio 2010中将Native / C ++ DLL链接到托管C ++ / CLI包装器