Я не уверен, если это то, что вы ищете, но смотрите ниже :)
Se пример ниже:
<?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('ruby ./test.rb', $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], 'hello world');
fclose($pipes[0]);
echo 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";
}
?>
Сохранить это как Сохранить как «тест. PHP ":
источник:
Run Ruby/Python from PHP Code
Вот еще один хороший пример:
//PHP script to execute ruby scripts when the host doesn't have a cgi handler for .rb
//Use with this .htaccess:
/*
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.rb$ handler.php?rb=$1.rb [NC,QSA]
*/
$file = $_GET['rb'];
if(in_array($file, scandir('.')))
{
foreach($_REQUEST as $key=>$value) if($key != 'rb') $args .= " $key=".urlencode($value);
echo exec(escapeshellcmd('./'.$file.$args));
}
else
{
echo '404- Page not found';
}
?>
С уважением
Daniel
Можете ли вы немного объяснить, как я могу использовать этот метод, если вы можете привести пример или что-то в этом роде. –
вы можете посмотреть [здесь] (https://www.practicingruby.com/articles/ways-to-load-code) – Kushal
@KushalMistry Можете ли вы добавить важную часть кода из ссылки, которую вы поделили в своем ответе , coz в течение времени, когда ссылки мертвы, и если кто-то в будущем хочет ссылаться, тогда это становится трудным. –