April 25, 201214 yr I have the following, which works locally. I need to convert it to read from a remote file, but I can't guarantee that allow_url_fopen will be available. I need to somehow refactor the following to use cURL or somesuch, but I can't seem to figure out how to do it line-by-line - all the cURL documentation refers to either echoing or returning the whole file. I can't do that, because the file might be too large. Ideas? I'm too tired for this. function pmp_import_read($file, $limit = 1) { // used for logging and limiting $row = 1; // Script will periodically reload from the last file pointer by location header, // passing the pointer as a GET var as it's run from WP cron rather than // true cron from shell $pointer = (isset($_GET['pointer'])) ? $_GET['pointer'] : ''; if (($handle = fopen($file, "r")) !== false) { // First line will always contain the headers $headers = fgetcsv($handle, 4096, ","); // Check if we need to move the pointer if (isset($pointer) && $pointer != '') { fseek($handle, $pointer); } // Loop through the rows until we hit limit while (($data = fgetcsv($handle, 4096, ",")) !== false && $row <= $limit) { if (count($data) > 1) { // Create associative array of headers and data $data = array_combine($headers, $data); // Insert/update categories $cat_id = pmp_process_categories($data['category']); // Insert/update product pmp_process_product($data, $cat_id); } else { // Log the error and continue pmp_log('Unable to import at line ' . $row); } $row++; } // Tidy up, get new position of pointer and return it $newpointer = ftell($handle); fclose($handle); return $newpointer; } else { // Couldn't open the file, no point continuing pmp_log('Unable to open file: ' . $file); return false; } Edited April 25, 201214 yr by Renaissance-Design
April 25, 201214 yr hey, Made a php lib so i can send push notifications to me android with platform updates, it dosnt use curl and uses php native stream wrapper so should work... https://github.com/snider/php-notifyMyAndroid/blob/master/nmaApi.class.php#L145
April 26, 201214 yr anno right, half the reason to making that lib is to remember that libcurl is not the nice way.... forever forggeting streams
Create an account or sign in to comment