PHP curl保持活动-CURLOPT_FORBID_REUSE

时间:2018-08-22 10:28:39

标签: php

关于CURLOPT_FORBID_REUSE,文档说(http://www.php.net/manual/en/function.curl-setopt.php

TRUE to force the connection to explicitly close when it
has finished processing, and not be pooled for reuse. 

如果设置为FALSE-我可以信任连接会被自动合并和重用吗,或者我需要做代码中特定的操作来支持它吗?即

  1. 我需要使用相同的手柄吗?即避免再次调用curl_init()并重复使用先前返回的相同值?

  2. 是否需要避免致电curl_close($ch)

1 个答案:

答案 0 :(得分:1)

  1. 不,您不必执行任何特定操作。这一切都是在“幕后”完成的。
  2. 您仍然需要调用 struct Vector4 { float values[4]; }; //I propose you two kinds of matrix, as is usualy done in linear algebra //left_matrix are efficient for matrix multiplication if they are on the //left side of the * symbol. struct left_matrix{ Vector4 rows[4]; //for this simple example we index using call operator: float& operator()(int i,int j){ return rows[i].values[j]; } }; struct right_matrix{ Vector4 columns[4]; float& operator()(int i, int j){ return columns[j].values[i];//the actual memory transposition is here. } }; right_matrix transpose_left_matrix(const left_matrix& m){ union{ left_matrix lm; right_matrix rm; }; lm = m; //lm is the active member return rm; //but we can access rm } 并获取您的句柄。
  3. 您仍然应该致电curl_init()

换句话说,curl_close()方法的接口保持不变。关于curl_*()标志的使用,您的代码不应更改。

CURLOPT_FORBID_REUSE包括但不限于关闭连接。还可以释放curl和php资源,进行清理。

但是,实际上,如果您怀疑所使用的服务器没有正确实现的HTTP延续,则只能使用curl_close()标志。