服务器可以访问代理但不能访问cURL?(Server accessible to proxies but not cURL?)
我用代理测试了我的本地服务器,我的朋友们都可以在他们的浏览器中加载url,但是当我尝试在单独的服务器上使用cURL时,它无法连接。
这是URL,它在我的浏览器上加载并使用我朋友的互联网:
http://pc.stephen3.com:8080/gameq.php
这是我在单独的服务器上使用的代码,它成功检索所有其他URL(如谷歌和雅虎)
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://pc.stephen3.com:8080/gameq.php"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $err = curl_error($ch); $resp = curl_exec($ch); echo $resp; echo $err;
但它在我的主服务器的URL上没有返回任何内容,并且
curl_error($ch);
(确实说,现在什么也没说)“无法连接到主持人”
任何想法可能是什么? 网址无处不在,但在cURL中。 代码可以在任何地方使用,但使用URL。
编辑:我想到,可能是因为我的外部服务器上的出站流量在端口8080上而不是普通服务器的80上,将不得不测试我的主机是否允许其他端口卷曲。
I have tested my local server with a proxy and my friends can all load the url in their browser, but when I try to use cURL on a separate server, it fails connecting.
Here is the URL, it loads on both my browser and using my friend's internet:
http://pc.stephen3.com:8080/gameq.php
Here is the code I am using on a separate server, it successfully retrieves all other URLs (like google and yahoo)
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://pc.stephen3.com:8080/gameq.php"); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $err = curl_error($ch); $resp = curl_exec($ch); echo $resp; echo $err;
But it returns nothing on my home server's url, and
curl_error($ch);
(did say, now says nothing) "couldn't connect to host"
Any ideas what it could be? The url works everywhere, but in cURL. The code works everywhere but with the URL.
EDIT: It occurred to me that it may be because of the outbound traffic on my external server being on port 8080 instead of 80 for regular servers, will have to test if my hoster allows curl on other ports.
原文:https://stackoverflow.com/questions/15190694
最满意答案
您必须编写自己的函数来指定要应用的各种函数:
multi.fun <- function(x,y) { c(mae = mae(x,y), mse = mse(x,y)) }
然后你可以这样做:
obs=data.frame(replicate(10,runif(100))) pred=data.frame(replicate(10,runif(100))) obs1=as.data.frame(lapply(obs, function(cc) cc[ sample(c(TRUE, NA), prob = c(0.85, 0.15), size = length(cc), replace = TRUE) ])) pred1=as.data.frame(lapply(pred, function(cc) cc[ sample(c(TRUE, NA), prob = c(0.85, 0.15), size = length(cc), replace = TRUE) ])) mapply(multi.fun, obs1, pred1)
You have to write your own function to specify the various functions you'd like to apply:
multi.fun <- function(x,y) { c(mae = mae(x,y), mse = mse(x,y)) }
Then you can do:
obs=data.frame(replicate(10,runif(100))) pred=data.frame(replicate(10,runif(100))) obs1=as.data.frame(lapply(obs, function(cc) cc[ sample(c(TRUE, NA), prob = c(0.85, 0.15), size = length(cc), replace = TRUE) ])) pred1=as.data.frame(lapply(pred, function(cc) cc[ sample(c(TRUE, NA), prob = c(0.85, 0.15), size = length(cc), replace = TRUE) ])) mapply(multi.fun, obs1, pred1)
相关问答
更多-
你几乎做对了。 你只是忘了R返回函数的最后访问元素。 在您的情况下,它只是每个数据框的子集,因此将函数设置为返回x并且它可以工作: set.seed(123) A = as.data.frame(matrix(sample(c('NA',1:10),10*10,T),10)) B = as.data.frame(matrix(sample(c('NA',LETTERS[1:10]),10*10,T),10)) C = as.data.frame(matrix(sample(c('NA',letters[1: ...
-
您的函数返回数据框不变,因为这是函数中评估的最后一项。 代替: columnselect<-function(df){ df[,c("Block","Name","F635.Mean","F532.Mean","B635.Mean","B532")] df} 它应该是: columnselect<-function(df){ df[,c("Block","Name","F635.Mean","F532.Mean"," ...
-
Alistaire在上面的评论中提供了正确的答案: Alistaire: 如果你给的不仅仅是一个函数的名字,你需要在你需要数据的地方放一个点: df %>% mutate_each(funs(do = . - max(.))) The correct answer comes from Alistaire in his comment above: Alistaire: If you're giving more than just the name of a function, you need to p ...
-
您必须编写自己的函数来指定要应用的各种函数: multi.fun <- function(x,y) { c(mae = mae(x,y), mse = mse(x,y)) } 然后你可以这样做: obs=data.frame(replicate(10,runif(100))) pred=data.frame(replicate(10,runif(100))) obs1=as.data.frame(lapply(obs, function(cc) cc[ sample(c(TRUE, NA), ...
-
您需要将代码放在一个以数据文件名作为参数的函数中。 然后,您可以使用相关的数据文件名调用您的函数。 就像是: library(doBy) library(ggplot2) library(plyr) library(raster) library(RColorBrewer) library(rgdal) library(scales) library(sp) #defining the function my.neat.function <- function(datafname){ ### Read i ...
-
使用pd.concat dflist = [df1, df2] keys = ["%d" % i for i in range(1, len(dflist) + 1)] merged = pd.concat([df.set_index('name') for df in dflist], axis=1, keys=keys) merged.columns = merged.swaplevel(0, 1, 1).columns.to_series().str.join('_') merged 要么 me ...
-
我认为这很简单: public static void main(String... args) throws IOException { ArrayList
> rows = getRandomData(); if (rows.size() == 0) throw new RuntimeException("No rows"); // normalize data int longest = 0; for (L ... -
如何在Pyspark中逐列连接/附加多个Spark数据帧?(How to concatenate/append multiple Spark dataframes column wise in Pyspark?)[2023-12-20]
下面是你想要做的例子,但是在scala中,我希望你可以将它转换为pyspark val spark = SparkSession .builder() .master("local") .appName("ParquetAppendMode") .getOrCreate() import spark.implicits._ val df1 = spark.sparkContext.parallelize(Seq( (1, "abc"), (2, "d ... -
我可以得到类似的东西 cut = lambda df: df[df.area > 10] cut(df) Per @root cut = 'area > 10' df.query(cut) Per @ayhan cut = lambda x: x.area > 10 df[cut] 定时 100行 df = pd.DataFrame(np.random.randint(0, 20, 100), columns=['area']) 1,000,000行 df = pd.DataFrame(np.ran ...
-
Grep多个数据帧(Grep multiple dataframes)[2021-08-10]
我们可以将数据集保存在list并使用“Gene”列上的grep检查“GeneX”,对行进行子集化。 lst <- lapply(mget(paste0("df", 1:12)), function(x) x[grep("GeneX", x$Gene),]) We can keep the datasets in a list and check for 'GeneX' with grep on 'Gene' column, subset the rows. lst <- lapply(mget(paste ...