<?php require_once './rollingcurlx.class.php'; $assetsFolder = __DIR__ . '/downloaded-assets'; $photos = array(); $data_file = $assetsFolder . '/data.json'; if (!file_exists($data_file)) { exit("Data file {$data_file} not found\n"); } $data = json_decode(file_get_contents($data_file)); if (json_last_error()) { exit("Data file {$data_file} parsing failed\n"); } $RCX = new RollingCurlX(10); $RCX->setCallback('cb'); foreach ($data as $id => $post) { if (!isset($post->full_picture)) { $photos[$post->id] = 'post has no image'; continue; } $file_name = getFileNameFromURL($post->full_picture); $file_path = $assetsFolder . "/photos/{$file_name}"; if (!file_exists($file_path)) { $RCX->addRequest($post->full_picture, NULL, NULL, array('id' => $id, 'path' => $file_path)); $photos[$post->id] = 'image download intitiated'; } else { $photos[$post->id] = 'image exists on disk'; } } $RCX->execute(); print_r($photos);