<分区> 分区>
我有一个基于 PHP Curl 的函数,用于应用程序中的各种请求。该函数通常用于在同一台机器(本地主机)上的其他服务器上通信/触发请求。函数如下:-
/**
* @desc If a curl_multi handle is passed, a new curl
* instance is added to the handle and the curl id is returned as string.
* @param string $theServer
* @param string $thePath
* @param number $thePort
* @param curl_multi $mcHandle
* @return string|curl_handle
*/
function sendPOSTtoURL($theServer, $thePath, $theData,
$thePort = 80, $mcHandle = null) {
global $bDebug; $theResult = ""; //$bDebug = true;
$cPost = curl_init();
if ($cPost !== false) {
curl_setopt($cPost, CURLOPT_URL, "http://".$theServer.$thePath);
if ($thePort != 80) curl_setopt($cPost, CURLOPT_PORT, $thePort);
// Set port if different from 80
curl_setopt($cPost, CURLOPT_HEADER, false);
curl_setopt($cPost, CURLOPT_FORBID_REUSE, true);
curl_setopt($cPost, CURLOPT_FRESH_CONNECT, true);
curl_setopt ($cPost, CURLOPT_POST, true);
curl_setopt ($cPost, CURLOPT_POSTFIELDS, $theData);
curl_setopt ($cPost, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($cPost);
if ($mcHandle == null) {
if (! $theResult = curl_exec($cPost)) {
if (curl_errno($cPost) > 0) {
$theResult = CURL_ERROR;
if ($bDebug)
$theResult .= fcURLError($cPost);
}
else {
$theResult = CURL_NOERR_NOINFO;
if ($bDebug)
$theResult .= fcURLError($cPost);
}
}
curl_close($cPost);
return $theResult;
} else {
curl_multi_add_handle($mcHandle, $cPost);
return $cPost;
}
} else return CURL_INIT_FAIL;
}
我不会讨论复杂性,但它设计用于在是单个请求时返回文本,或者在传递 multi_curl 句柄时附加 curl 句柄。
问题是,当我请求它在远程服务器上执行任务时,它会执行双重请求。我们有一个设置,其中请求服务器通过 VPN 连接到远程服务器,并且可以通过它向外部 Internet 发出请求。我认为目标服务器运行了两次,所以我从调用服务器调用了一个电话(用于发送电子邮件),如下所示:-
$aEmail = array("email_address" => $sEmailAddress,
"email_subject" => $sEmailSubject,
"email_body" => $sEmailBody);
echo sendPOSTtoURL("<REMOTE IP HERE",
"/emailService/doMail.php?rand=".mt_rand(),
$aEmail);
对 mt_rand 的调用会生成一个随机数,因此我可以识别每个请求。这是我在远程服务器上得到的:-
<CALLING IP> - - [15/Jun/2011:20:39:57 +0500] "POST /emailService/doMail.php?rand=1551627310 HTTP/1.1" 200 1060 "-" "-"
<CALLING IP> - - [15/Jun/2011:20:40:01 +0500] "POST /emailService/doMail.php?rand=1551627310 HTTP/1.1" 200 1060 "-" "-"
如您所见,同一个请求出现了两次。你认为会发生什么?对,给目标发了 2 封电子邮件!我不能(由于管理 [S@#$] 原因)开发逻辑来在远程服务器上处理此问题。
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
我有一个在Linux服务器上运行的ruby脚本。它不使用rails或任何东西。它基本上是一个命令行ruby脚本,可以像这样传递参数:./ruby_script.rbarg1arg2如何将参数抽象到配置文件(例如yaml文件或其他文件)中?您能否举例说明如何做到这一点?提前谢谢你。 最佳答案 首先,您可以运行一个写入YAML配置文件的独立脚本:require"yaml"File.write("path_to_yaml_file",[arg1,arg2].to_yaml)然后,在您的应用中阅读它:require"yaml"arg
我是Rails的新手,所以请原谅简单的问题。我正在为一家公司创建一个网站。那家公司想在网站上展示它的客户。我想让客户自己管理这个。我正在为“客户”生成一个表格,我想要的三列是:公司名称、公司描述和Logo。对于名称,我使用的是name:string但不确定如何在脚本/生成脚手架终端命令中最好地创建描述列(因为我打算将其设置为文本区域)和图片。我怀疑描述(我想成为一个文本区域)应该仍然是描述:字符串,然后以实际形式进行调整。不确定如何处理图片字段。那么……说来话长:我在脚手架命令中输入什么来生成描述和图片列? 最佳答案 对于“文本”数
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
有这些railscast。http://railscasts.com/episodes/218-making-generators-in-rails-3有了这个,你就会知道如何创建样式表和脚手架生成器。http://railscasts.com/episodes/216-generators-in-rails-3通过这个,您可以了解如何添加一些文件来修改脚手架View。我想把两者结合起来。我想创建一个生成器,它也可以创建脚手架View。有点像RyanBates漂亮的生成器或web_app_themegem(https://github.com/pilu/web-app-theme)。我