Similar Posts
Debugging Webhooks
A webhook is an HTTP callback, that occurs when something happens (a resource changes its state). Webhooks provide a way to build event-driven apps, because you can be notified about changes. Since webhooks require a publicly accessible URL to function they can be hard to test from your local machine. There are three main problems…
Retrying and Logging Requests with Guzzle
When consuming 3d party API, you may want to do two things: In this article we will look at how to implement the above features using Guzzle, a popular PHP library for making API calls. Let us scaffold our app composer init composer require guzzlehttp/guzzle:~6.0 composer require monolog/monolog composer require –dev phpunit/phpunit:^8 We will be…
Replace Funky Characters While Importing CSV
Sometimes uploaded text/csv file may have non-utf8 or other funky characters using the function below. public static function processUploadedBundles($request) { $content = file_get_contents($request->file(’uploadedFile’)->getRealPath()); $lines = explode(PHP_EOL, $content); $array = []; foreach ($lines as $line) { $arrayCsv = str_getcsv($line, ","); $arrayCsv = array_map(function($value){ return preg_replace(’/[\x00-\x1F\x7F-\xFF]/’, ”, $value); }, $arrayCsv); $array[] = $arrayCsv; } return…
Complex Eloquent Query
A query below selects products that need to be updated in a remote application. It takes quantities of products in host application that are connected to source products application. On top of that it looks at all the orders that are in “Pending” status and reserves quantities for those products. SELECT products.quantity_available, connector_products.stock_id, products.id, connector_products.sku,…
Large CSV Export
Sometimes you need to export a large amount of data from your database. Obviously, if you are going to accumulate all data in an array and then write it to a csv file, you will eventually run out of memory. A better solution is to use streams. Here is how you can export data from…