私はwampで作業していましたが、同じディレクトリにすべてのファイルを持つことができたので問題はありませんでしたが、今はホストサーバーを使用しています。 PYファイルが機能するようになります。 Hello.php
は/public_html/wp-content/plugins
にあり、そのPHPが動作しているPYは/public_html/cgi-bin
です。私は$application_path .= plugin_dir_path(__FILE__);
$application_path = $_SERVER['DOCUMENT_ROOT']; $application_path .= "/public_html/cgi-bin/hello.py";
には何もしなかった変更しようとしているディレクトリを変更するには? PHPで
<?php # -*- coding: utf-8 -*-
/* Plugin Name: hello */
header('Content-Type: text/html; charset=cp1252');
add_shortcode('hello', 'execute_python_with_argv');
function execute_python_with_argv(){
ob_start();
$description = array (
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
);
$application_system = "python ";
$application_path .= plugin_dir_path(__FILE__);
$application_name .= "hello.py";
$separator = " ";
$application = $application_system.$application_path.$application_name.$separator;
$pipes = array();
$proc = proc_open ($application , $description , $pipes);
if (is_resource ($proc))
{
echo stream_get_contents ($pipes [1]); //Reading stdout buffer
}
echo "soup";
$output = ob_get_clean();
return $output;
}
:これはhello.phpコードです。どんな助けでも、読んでいただきありがとうございます。
すごいああ、ありがとう!私は 'cgi-bin'ディレクトリにいますが、何らかのエラーが発生しました。[28-Jun-2016 10:20:53 UTC] PHPの警告:/ home/meteodatのセキュリティ上の理由からproc_open()が無効になっています/public_html/wp-content/plugins/hello.php on line 18' – MakeMeWise
このエラーがあなたのシステムに入っている理由はわかりませんが、php.ini *ファイルのdisable_functionsからproc_open文字列を削除することができます –
私のホストは言ったphp.iniはすべてのユーザーに適用され、変更することはできませんが、他の方法はありますか? – MakeMeWise