如何将 $_POST 值从 ruby 脚本传递到 php 脚本
我需要运行 cron 作业来使用 Redmine 的 reposman.rb 添加 svn 存储库。但我们还有一个 php 脚本(带有界面),使我们能够自动创建存储库。
php 脚本接收 $_POST 值,创建存储库,设置权限,分配一些组以对新创建的存储库进行读写访问。
我的问题是:
- 如何执行 php 脚本,而不是 reposman.rb 中的 svnadmin create 命令?
- 我如何为 php 脚本提供 $_POST 参数,以便它可以使用 php 脚本正确设置我的 svn 存储库。
谢谢
编辑: 以下是这两个脚本的作用的一些示例。
Ruby 脚本:
... // Add the repos system "svnadmin create #{path}" ...
Php 脚本:
// Receive the name of the repos to add $dir= $_POST["dir"]; // Do all the stuff with the permissions $cmd= "sudo /usr/local/bin/createsvnrepo $dir"; system("$cmd", $retval); ...
I need to run a cron job to add a svn repository using reposman.rb for Redmine. But we also have a php script (with an interface) that enable us to create repositories automaticly.
The php script receives a $_POST value, create the repos, sets permissions, assign some group for read and write access to the newly created repos.
My question is this:
- how could I execute the php script, instead of the
svnadmin create
command in reposman.rb? - How can I give a $_POST parameter to the php script, so it could setup my svn repos correctly, using the php script.
Thanks
Edit:
Here are some example of what both scripts do.
Ruby script:
... // Add the repos system "svnadmin create #{path}" ...
Php script:
// Receive the name of the repos to add $dir= $_POST["dir"]; // Do all the stuff with the permissions $cmd= "sudo /usr/local/bin/createsvnrepo $dir"; system("$cmd", $retval); ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果可以更改脚本,它应该通过文件或标准输入获取输入数据。如果不是,您可以编写一个包装器脚本,从文件/stdin 中选取数据,用它填充
$_POST
(是的,PHP 超全局变量是可写的)并通过require
调用原始脚本代码>.If it's possible to change the script, it should be getting its input data through a file or standard input. If it's not, you can write a wrapper script that picks data from file/stdin, populates
$_POST
with it (yes, PHP superglobals are writable) and calls the original script throughrequire
.向您的脚本发送 http 请求 - $_POST 不打算从命令行初始化。
Send http request to your script - $_POST is not intended to be initialized from command line.
您可以使用以下方法伪造对 PHP 脚本的 POST 请求:
(好吧,它实际上比“假”更“实现”)
请注意,它确实需要
php-cgi
二进制文件,而不是普通的 -cli 版本。并且您需要复制所有CGI 环境变量。因此,修改现有脚本以接受 $argv 参数可能会更容易。You can fake a POST request to a PHP script with:
(well, it's actually more "implement" than "fake")
Note that it really requires the
php-cgi
binary, not the normal -cli version. And you need to replicate all of the of the CGI environment variables. So it might be easier to just modify the existing script to accept $argv parameters instead.您可以从命令行运行该脚本。
像这样的东西:
You can run the script from command line.
Something like this:
这里需要使用 php 命令行界面 (php_cli)。您没有 $_POST,但您可以提供传递给 php 脚本的参数。从 ruby 进行系统调用来执行 php 脚本(我不知道 ruby,所以我只发布 php 部分)。在你的 php 脚本中,从正确的 shabang 开始:
调用应该类似于:
./myscript.php -v=value1 -b=value2
检查 $_SERVER['argv'] 中传递的值
You need to use the php command line interface here (php_cli). You don't have $_POST, but you can provide arguments to pass to the php script. Do a system call from ruby to execute the php script (i dunno ruby so i only post the php part). In your php script start with the right shabang:
The call should be something like:
./myscript.php -v=value1 -b=value2
Check the $_SERVER['argv'] for the values passed
因为@Richard Knop 的评论对我的帮助超过了任何答案,所以我将回答我自己的问题来帮助其他人。
我使用 curb 将帖子发送到 php 脚本。
reposman.rb
Since, @Richard Knop's comment helped me more than any answer, I will answer my own question to help others.
I used curb to send a post to the php script.
reposman.rb