有轮子的时候用轮子 ... 没有轮子的时候就自己造一个轮子好了 ...
好吧其实我就是突然有一点点闲时间可以帮你写写代码这样 ...<?php
/* put your text file location here ... */
define( 'TEXT_SRC', '/path/to/your.text.file.txt' );
/* put the url which you wanna post data to here ... */
define( 'DATA_URL', 'http://the.url.data/goes.to' );
/* put post field name here ... */
define( 'POST_PFX', 'data' );
/* read million data from source ... */
$text_src = file(
TEXT_SRC, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES
);
/* hey here comes cURL ... */
$curl = curl_init();
/* prepare cURL and make a very fashion UA header ... */
curl_setopt_array( $curl, [
CURLOPT_URL => DATA_URL,
CURLOPT_USERAGENT =>
'Mozilla/1.22 (compatible; MSIE 2.0; Windows 3.1)',
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_POST => 1,
] );
/* something to handle cURL result ... */
$callback = function( $result ) {
return;
};
/* time for our BIG LOOOOOOOP ! */
foreach( $text_src as $data ) {
/* fill data ... */
curl_setopt( $curl, CURLOPT_POSTFIELDS, POST_PFX . '=' . $data );
/* and send them out ! */
$callback( curl_exec( $curl ) );
}
/* you have had a long flight ... time for rest ... */
curl_close( $curl );
运行的话需要 php 5.4.0 以上的版本和 cURL 扩展 ... 前三行是配置区需要自行修改 ...
另外程序是以牺牲内存为代价提升效率的 ... 因为我觉得说只有几十万行的话应该文件不会太大 ...
程序会把那个文本文档一股脑读进内存 ... 所以如果要处理更多数据的话还要修改 ...
恩 ... 就是这样 ... 看看是不是你想要的效果呢 ..?