Three survival tools for an inhospitable (production) environment

As a web developer, you may need to deal with your client’s production environment. Sometimes it’s not the easiest environment to work with, like in a shared hosting or a limited

I already worked with some clients that I wasn’t able to remote connect to the database. Others didn’t allow me to connect to a regular FTP service, all files had to be transferred one by one via a Web FTP.

Over the years I’ve put together some tools to help me with those situations.Other than small snippets and scripts, here are three of the tools that I must used in the last eight years.

Adminer (formerly phpMinAdmin)

Adminer is a single file database management tool written in PHP that can handle MySQL, PostgreSQL, SQLite, MS SQL, Oracle, Firebird, SimpleDB, Elasticsearch and MongoDB. Useful since most of the free database GUI tools doesn’t offer Tunneling connections.

MySQL BigDump

BigDump allows you to import massive and large MySQL dumps. It works well very limited servers.

phpFileManager

phpFileManager can help you when you don’t have FTP access to the hosting. It’s multi-uploader and compress/extract are very convenient.

Conclusion

I know that the use of such hostings are decreasingly over the years. But we, as developers, must be prepared to such sittuations. I hope my tips here can help you someway.

Setting up a half-assed PHP development environment on Windows

I, personally, don’t like to develop on Windows, but sometimes I am sitting at my desktop computer(that I use mainly for gaming) and need to code or fix something. Here I will present the setup that I use.

Cygwin64

Have you ever wondered to use git, gcc, make and even emacs on Windows? Cygwin is the easy way to achieve that. Download and run the Cygwin installer. The base package works fine, but make sure to install net/openssh and devel/git packages are selected.

Now just set your system’s PATH environment variable including the cygwin /bin/ folder path.

ConEmu

conemuThis step is not entirely necessary, but I don’t regret using it. Download and install ConEmu. Open the Settings (Super+Alt+P), select the Startup entry from the tree menu and select Specified named task to Cygwin Bash.

 

Vagrant and Scotch Box

I used to roll my Vagrant boxes using PuPHPet. Recently on Windows I had some issues with shared folders settings, I am now using the preconfigured box from Scotch Box.

First download and install VirtualBox and Vagrant. Then clone and setup with vagrant, the first time will take a while since Vagrant need to download the image.

git clone https://github.com/scotch-io/scotch-box.git scotchbox
cd scotchbox
vagrant up

Before shutting down your computer, you should suspend your box.

vagrant suspend

You can ssh into your box using the following command:

vagrant ssh

Visit http://192.168.33.10/ to access your box.
This setup is far from perfect, but it works for me. A while ago I used JetBrains PhpStorm as IDE to develop, recently I changed to Atom simply because it loads faster and I don’t use all the features of PhpStorm.

Parsing websites with curl and phpQuery

A while ago I had to crawl some websites to gather information about products. In the past I’ve used RegExp to parse the HTML, knowing it’s not the best method, but I just felt that PHP’s DOMDocument was clumsy.

I started coding the crawler with CakePHP 2.5.x and the following classes: electrolinux/phpquery and php-curl-class/php-curl-class.

The php-curl-class is pretty straight forward, it’s just easier to work with curl with it. In addition, the phpQuery is a library that let’s you use CSS3 selectors just like you do with jQuery.

I know it’s lame, but as example let’s get the title of SaveWalterWhite.

<?php
$curl = new \Curl\Curl();
$curl->get("http://www.savewalterwhite.com");
$pq = phpQuery::newDocument($curl->response);
echo $pq->find('title')->text();
?>

Obviously you can do more complex stuff, like getting all the image paths that are inside list items of the #walter-container div.

<?php
$curl = new \Curl\Curl();
$curl->get("http://www.savewalterwhite.com");
$pq = phpQuery::newDocument($curl->response);
for ($i=1;$i
$pics = $pq->find('div#walter-container li img')->attr('src');
if (!empty($pics)) { var_dump($pics); } 
?>

You can also use the selector on an iteration like this:

<?php
for ($i=1;$i<=$limit;$i++)
{
 $pics = $pq->find('div#product-detail ul li:nth-child('.$i.') a')->attr('data-image-zoom');
 if (!empty($pics))
 {
 $images[] = $pics;
 }
 }
?>

Checkout the phpQuery manual for further information. This class is handy and saved me a lot of time.