Tag: development

  • WooCommerce delayed webhooks using actions scheduler

    Recently been contacted by a user who needed the ability to delay the WooCommerce webhooks by x time, this would allow other processes happening on the site to finish instead of firing the webhook straight away, for example waiting for the payment process to finalise. Delaying webhooks is not common practice, however some time special case arises!

    Take a look at actions scheduler if you wish to read more into the scheduler system used by WooCommerce.

    Code

    The following code allows you to delay several WooCommerces webhooks by a set duration (seconds) and also run in two modes.

    1. Single Webhook, creates 1 single webhook but delayed by x seconds.
    2. Multi Webhook, creates 2 webhooks, the normal webhook created by WooCommerce and a second repeat webhook which runs x seconds later.

    This code is provided as it and may require changes to work for your needs.

     

  • WooCommerce fix slow or delayed webhooks and achieve instant webhook firing

    I’ve recently been working on a project which synced data between WooCommerce and an internal warehouse system, I was utilising the WooCommerce webhooks to achieve near real time syncing between the two systems, without having the creating API scripts to poll for data on a regular basis.

    The Problem?

    There was a delay ranging from couple seconds to 1 minute, WooCommerce uses a system called actions scheduler, this is an improved wordpress cron, allowing background processing to occur within WordPress for single or recurring actions. This is great and what WooCommerce utilises for its web hook system, however it is backed by the word press cron and the next load of scheduled actions will run on the next cron run (every 1 minute).

    For this project, I needed the web hooks to fire as soon as the button was clicked, and a possible delay up to 1 minute was to long.

    Fix

    Disable async web hooks, web hooks will not fire as soon as they are created as part of the browser request.

    I would recommend you test your site after doing this change, for example order webhooks will fire when a customer creates a new order, which could lead to a slow user experience.

  • Control windows docker with Windows 10 Ubuntu Linux subsystem

    Windows 10 Linux subsystems are a very powerful feature and expand the capabilities for Windows based developers greatly, without the need to use VMs or dual booting. One of these is controlling your windows based docker host via your Linux subsystem.

    Why?

    Linux command line is much more powerful that windows standard cmd line, you can combine a number of tools using piping to perform complex operations all via cli. Many of the tutorials, guides and normal operating commands used by docker and other tools are written using Linux based command line.

    1. Setup Linux Subsystem

    First you need to have your linux subsystem all setup and running. here is a guide I previous wrote to do just that.

    All commands below will be via your linux subsystem.

    Windows 10 Subsystem for Linux Ubuntu

    2. Updates and packages

    3. Add Docker’s official GPG key

    4. Add repository

    5. Install docker client

    6. Add docker host to bash profile

    This is so that you dont have to keep telling docker client how to access the docker service.

    7. Enable exposed daemon with docker

    We are almost done, now we just need to go back to our windows system and enabled exposed daemon via the docker settings.

    Right click the docker icon within your task area and choose settings.

    The general tab should have a “Expose daemon on tcp://localhost:2375 without TLS”, enable this option.

    You should now be able to control your Windows docker service via your Linux subsystem.

    Note

    There is a more secure way to establish a connect between your subsystem and docker client, have a look at the following guide.

    [Cross Post] WSL Interoperability with Docker

  • Windows 10 Subsystem for Linux Ubuntu

    I have always been more of a Windows based developer and used Linux based systems for server technologies, I have tried in the past to move to Linux but I am to fixed in my way and prefer the tools I have on windows! Is that a bad thing, I dont no? however with Windows 10 comes Subsystems which allows you to run a Linux based Ubuntu as part of a subsystem working jointly with your windows 10 operating system.

    Im not talking about a VM or dual booting, I am talking about the ability to go to windows command line and type “ubuntu” and a full fledged ubuntu system from the command line starts up and allows you to run various tools, applications and services all within Ubuntu within Windows 10!

    Microsoft site has a simple guide to follow to install the linux subsystem here.

     

    1. Enabled windows subsystems for Linux

     

    2. Install Ubuntu via Windows Store

    Open Microsoft Store and search for Ubuntu and click install
     

    3. Initialise Setup

    Open command line and type ubuntu to start the ubuntu instance, it will take you throught a initialisation stage

     

    What next? have play around with Ubuntu on windows. For development purposes I am going to be using it with Docker! allowing me to control my Windows Docker environment from the Ubuntu Linux, as it allows me to use all the Linux based command structures and pipes making the experience even smoother and more powerful.

  • Twitter Bootstrap 3 Media Queries

    Some useful bootstrap 3 media queries for both mobile first and non mobile first development styles, to make modifications to your front end simplier and follow the bootstrap 3 standard breakpoints.

    Origional article can be found here.

    Min-Width: Refers to everything greater than or equal to the amount given.
    Max-Width: Refers to everything less than or equal to the amount given.

  • Local website & services remotely accessible via secure tunnels with ngrok

    Need an easy way to allow external network users to access services or websites on your local machine? ngrok allows you to easily create a secure tunnel from ngroks servers to your machine. For a web developer, this is a dream come true, this is a great way to demo a development whilst in the early stages, saves time uploading to a server.

    • Allows access to your locally hosted web server from a unique domain
    • Can use your own domains
    • Works with vHost files
    • Allows testing of website which require an external accessible point such as payment gateways or oAuth
    • Can tunnel other services such as PhoneGap allowing users external to your network to test your mobile app
    • Various API and IoT implementations
    • Easy / quick private networking, VPN benefits

    These are only a short list of what is possible using ngrok. Look at their website for a full list of its powerful features and get started.

    https://ngrok.com/

  • Laravel, time zones and carbon

    Laravel defaults to storing all dates in UTC format, this is highly recommended as UTC time never changes unlike other time zones which have daylight savings. It is best practice to store and read dates in UTC, and then convert UTC to your required time zone for the user interface.

    Great article below of a good way to implement time zones using Carbon within your Laravel app.

    https://andrew.cool/blog/49/Easy-timezones-in-Laravel-with-Carbon

  • Easy mobile browser detection for several major languages and web servers

    All app’s and websites these days need to work for several devices including desktop, tablets and mobiles. It’s not always simple detecting the type of device being used and it can sometimes be tedious adding support to your app for something which seems very simple.

    Does your chosen platform not have a pre-defined way of detecting a mobile browser? Check out Detect Mobile Browsers, has several copy / paste examples for several programming languages.

    http://detectmobilebrowsers.com/

    Remember Apache, IIS and nginx detection examples also present for doing for pesky redirects.

  • Progressive JPEGs for fast website image loading and ux design

    Want to Speed up your website images and improve user experience? Make sure you use progressive JPEGs (or interlaced JPEGs), it could help make your website load faster and retain visitors for a longer duration.

    Take a look at the example below showing a normal baselayer JPEG and a progressive JPEG LOADING side by side.

    http://pooyak.com/p/progjpeg/

    Instead of delaying page loading for high quality images, we can display lower quality and load the high quality whilst the user can still browser, view, read and purchase. Remember your visitors may be on a slow mobile connection! They don’t want to wait!

    Some further reading? Take a look at the website below.

    https://www.thewebmaster.com/dev/2016/feb/10/how-progressive-jpegs-can-speed-up-your-website/

  • PHP: Show PHP errors messages for debugging code

    PHP: Show PHP errors messages for debugging code

    Need to easily debug some php code? simple add the following code to your script to enable PHP error reporting and display error messages. This allows you to quickly debug without making configuration changes to servers PHP configuration.

    It is good practice to hide error messages for security reasons, error messages could be used by hackers to gather information and vulnerabilities.

    This code is provided as it and may require changes to work for your needs.