Praj's Blog

$_SESSION global is empty

If you find that your global $_SESSION variable is empty there can be several reasons, here are a few:

  • The session.save_path is invalid (does not exist) or is not writable.
  • The session.cookie_secure is set to true but you not using a secure site (SSL/https).
  • The session.cookie_domain is set to a domain that does not match your site – very common if setting up a dev or test environment from a production site with a public domain.

soapUI 5.x hangs on Mac OSX

I’ve had this issue on OSX Mavericks and Yosemite on soapUI 5.x versions. Here’s a fix that disables the browser in soapUI which seems to cause it to hang.

Open /Applications/SoapUI-5.2.0.app/Contents/ (adjust to suit your version).

Editvmoptions.txt and add line: -Dsoapui.browser.disabled=true

Open /Applications/SoapUI-5.2.0.app/Contents/java/app/bin (adjust to suit your version)

Edit soapUI.sh and uncomment line: -Dsoapui.browser.disabled=true

Escaping variables inside other variables in bash scripts

Say you have a variable that comprises of another variable like so:

var_name=test
var_name_full=$var_name_and_extension

The above won’t work as bash will interpret the underscore after $var_name as part of the variable name and look for a variable called $var_name_and_extension and not find it.

Two ways to solve this:

Enclose in curly braces as follows:

var_name=test
var_name_full=${var_name}_and_extension

Use double quotes to delineate between the variable name and the string:

var_name=test
var_name_full=$var_name"_and_extension"

Find constants in your PHP code base

The following grep command will search for any constants such as define('CONSTANT', 1) within your PHP code base so you can see their values. Useful as many applications store the constant’s value in the database and not the constant’s friendly name.

This requires regular expressions, hence the use of egrep.

egrep --include *.php "(define)(.*)" -r *

Mac Slack Client Keeps Crashing

Found this morning that my Mac Slack client (v1.13, build 2813) kept on crashing on start up (I’m running Mac OSX 10.9 Mavericks). It was working fine until the latest Mac update (Security Update 2015-006 version 1.0 18/08/2015).

The crash reporter tells me something along the lines of this:

  Application Specific Information:
  *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not make an sqlite3 statement for: CREATE TABLE IF NOT EXISTS downloads (team         TEXT NOT NULL, token        TEXT NOT NULL, href         TEXT NOT NULL, state        TEXT NOT NULL DEFAULT 'pending', http_status  TEXT NOT NULL DEFAULT '', file_path    TEXT NOT NULL DEFAULT '', file_exists  TEXT NOT NULL DEFAULT 'false', mime_type    TEXT NOT NULL DEFAULT '', start_ts     TEXT NOT NULL DEFAULT '', end_ts       TEXT NOT NULL DEFAULT '', base64_png   TEXT NOT NULL DEFAULT ''); | (
  )'
  terminating with uncaught exception of type NSException
  abort() called

Uninstalling/reinstalling didn’t fix the issue. I ended up deleting the following folder in my home directory:

~/Library/Containers/com.tinyspeck.slackmacgap

This obviously holds some sort of data, so I’m not sure of the entire consequences of doing this. For a start, you need to sign into all your accounts again. It doesn’t appear to impact your slack history or anything like that.

Converting strings to dates in MySQL

Use the str_to_date function and provide the format you need to it. for example, if you have a field called created_dttm with a date which is in the format “24-07-2015 06:00:00” you can use this to convert into a MySQL date so that you use various MySQL date functions on it.

select str_to_date(created_dttm, '%d-%M-%Y %H:%i%s');

See this list for all the date formats.

Wireless Router & Headset conflict

I have an ASUS AC68U wireless router and lLgitech G930 wireless headset, and I kept finding that my headset with drop out. After some research, I came to the conclusion that I should try changing the wireless control channel on my router.

The control channels range from 1 to 11, so the best options to avoid interference are 1, 6 or 11 (i.e either end or the middle of the spectrum). I tried 11, then 6 and both weren’t much better, however control channel 1 seemed to do the trick. You can tell it works because a restart of the wireless on the router after changing the channel would cause a drop out, and this happened immediately on channels 6 and 11, but not on 1.