我有来自CodeCanyon的这个脚本ProtectedLinks。它使用表单输入进行临时链接。我需要它的功能。所以我决定使用CURL。首先,我做出了正确的决定吗?
在我的项目中,我必须发送30个CURL请求(直接链接和页面所需的其他$ _POST数据,这些数据将这些数据转换为临时链接并将其存储在数据库中)到此页面。这是一项重度的工作。
它有时会使我的页面停止并插入一半非常不愉快的数据。我该怎么办?
我是否有办法发送一个请求,其中一个数组包含所有数据,同时执行相同的操作。
这是我的数据:
$fields = array
(
'url' => $url_to_be_coded,
'f_name' => "Package " . $product_id,
'f_title' => "Package " . $product_id,
'f_desc' => "Part" . $part,
'usertype' => 'm',
'exptime' => '72',
'exprespect' => 'L',
'authority' => "User Requested Again",
'part_number' => $part
);
我想在一个请求或电话中发送大量信息。使用相同的键,其中数组中的项目数量不明确。当然,在着陆页中处理这些数据
答案 0 :(得分:2)
Did I make the right decision?
- 是的,对我来说听起来不错。
It sometimes make my page stop and insert half data which is very unpleasant. What should I do?
f是什么?正如@Johnson在评论中所说,将它包装在一个事务中,所以它变成了一切或什么都没有,但也试图找出为什么这有时会发生,它不应该...... php最大执行时间? nginx proxy_read_timeout? php ignore_user_abort()? CURL CURLOPT_TIMEOUT?不管它是什么,追踪它,并在可能的情况下修复它。它会在错误日志中生成任何内容吗?
I want to send a lot of this, in one request or call. with the same keys where number of items in array is not clear. and of course process this data in landing page
- 没问题,不是接受单个字段数组,而是更改代码以接受字段数组,并将当前字段处理代码包装在foreach($_POST as $field){/*process single field just like in the old code*/}
$fields=gzcompress(http_build_query($fields),9);
和CURLOPT_HTTPHEADER=>['Content-Type: application/x-www-urlencoded','Content-Encoding: gzip'];
并在服务器上执行
if($_SERVER['HTTP_CONTENT_ENCODING']==='gzip'){
parse_str(gzuncompress(file_get_contents('php://input')),$_POST);
}