PHP, work queues

PHP, work queues

Biggest pain point in PHP is lack of asynchronous calls. The only reasonable way is to use some kind of “backend” processing and task list to execute. Some people use cron to run given script each n-minutes and execute tasks. But there is a little bit more “professional” approach.  Beanstalk is a simple, fast work queue. Idea is pretty simple – you can just throw tasks into queue and then have background worker which is pulling data from pipe and executes task.

Couple ideas: sending emails, processing images, making heavy queries into database. But the best part of it – you don’t have to use PHP for back processing. It could be anything, because protocol us universal and worker and client doesn’t have to be in the same language. So you can schedule task in PHP, and run it in Go. I’m not going too much into details. Just run some examples.

Reading unknown JSON object in go language

Reading unknown JSON object in go language

Exploring [The Go Language][1] is so much fun. Everything is brand new, and different then any other language. This time I’m going to show quick snippet which shows how to read JSON object with unknown structure, and map elements to something like hash table.

CentoOS 7 NFS support

CentoOS 7 NFS support

CentOS is pretty new, and some default stuff is just missing. Like NFS suport out of the box.

We have to install package called nfs-utils

yum -y install nfs-utils

we can mount using standard mount 192.168.1.15:/c/share

mount -a 

to make it parmament

edit /etc/fstab

192.168.1.15:/c/share /mnt/nfs nfs defaults 0 0
Fetch page with proxy using The Go language

Fetch page with proxy using The Go language

For a while i’m playing with The Go Programming Language – so far I loved it. I figure out that I’ll push some code snippets from time to time.
Today I spend some time creating simple not ever crawler, but website fetcher.

Idea is very simple – download page, run xpath query on it and spit out results. I was looking for decent xpath library for Go and couldn’t find any. I tried to use xmlpath but it sucks. I couldn’t even run queries like id('product-details')/div[@class='product-price']" Then I found something nicer – Gokogiri – which works pretty nicely, but – couldn’t find any examples except this small article .

The only problem with running Gokogiri is that it uses libxml2 which is not a huge problem on Linux based systems, but on Mac OS X you have to install it via homebrew
brew install libxml2