douguan1887 2017-04-06 15:23
浏览 85
已采纳

与popen平行的过程

I need to download files from many web servers and then do somethigs. Some files are big. Each downloads it's independent from another so I want to do in parallel.

So I write the following scripts:

test.php

$urls = [
    'url1', 'url2', 'url3'
];

foreach($urls as $url){
    popen("php download.php --url=" . $url, "w");
}

download.php

$options = getopt(null, ["url:"]);
$url = $options["url"];
// do somethings - This loop is just for testing purposes
for($i = 0; $i <= 1000000000; $i++){
    $i;
}
print parse_url($url)["host"];

When i run php test.php console show me a sequencial output. What am I doing wrong?

  • 写回答

2条回答 默认 最新

  • doupeng8419 2017-04-08 00:41
    关注

    Finally, I found the best solution.

    Pool was covered all my requirements. Pool-worker is a software design pattern in such Pool is a container and has many Workers (Process waiting for tasks). tasks are added to the pool and then, each worker take a task to exec.

    By the other hand, I think that Python's implementation is better that PHP's implementation of Pool-worker pattern than PHP.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程