PHPMyAdmin is not working with MAMP: Cannot start session without errors

Posted in MySQL, PHP, PHPMyAdmin on April 24th, 2013 by Comments Off

For no apparent reason, PHPMyAdmin from MAMP on my local development environment stopped working and only displayed the following error.

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

The first thing I tried was to see if there was an error that was logged to the PHP error log.

tail /Applications/MAMP/logs/php_error.log

There were no PHPMyAdmin related errors in the log. The problem was clearly with sessions because that is what the error message says, “Cannot start session without errors.”

The solution for me was to clear all sessions from the MAMP tmp directory for PHP and add more permissions to the folder.

sudo rm /Applications/MAMP/tmp/php/sess_*
sudo chmod 0777 /Applications/MAMP/tmp/php/

I ran the above commands and then restarted MAMP. Everything was back to normal.

VPS.NET is inconsistent at best; a year of disappointment

Posted in Cloud Technology, Miscallaneous on March 2nd, 2013 by Comments Off

I believe in cloud technology. I understand the benefits and the potential for virtually limitless scalability. Over the past year, I have advised my customers and clients to host their websites and various services on cloud servers. When I started doing this, I chose VPS.NET as the cloud server provider that I recommended and worked with on a daily basis. I chose VPS.NET because they have a robust API and very competitive pricing, not to mention the abundant server locations around the world. VPS.NET looks great!

VPS.NET

VPS.NET

When I started using VPS.NET, everything seemed to work as it should. I was able to deploy servers, install software, and get websites and services up and running without a problem. There was a period of a month or two where I did all the development and the testing with my client at the time. During this time, there was no down time or other type of interruption in service, but when the service based business went live for my first customer that I brought on board with VPS.NET, my experience with VPS.NET changed as quickly as weather in Texas. Unfortunately by this time, the client and I were too invested in VPS.NET to take a step back and re-think our server provider. We had to ride it out. Nearly a year later, we are still riding it out.

“InformationWeek estimates downtime causes 26.5 billion dollars in lost revenue each year. Our auto healing technology is a key step in preventing your business from losing sales, productivity and clients. The Cloud Infrastructure powering our Cloud Servers is able to detect an outage as it happens, and can then move your Cloud Server, unharmed and uninterrupted, to a new location in the cloud, where it stays online, and you stay in business.” – VPS.NET

The VPS.NET network is not as agile and rapid to adapt as they claim it to be. Over the past year, I’ve experienced more down time and interrupted service with VPS.NET than with any other server provider in the past decade. The problems range from random server reboots to frequent connectivity issues like packet loss and dropped connections.

In the last 10 months, I have opened 80 support tickets for just one of my customers that I introduced to VPS.NET. This comes to two tickets per week.

While VPS.NET has quick support ticket response times, I am not satisfied with the level of responses I have received from their staff. Many of my tickets have been swiped under the carpet with generic explanations excuses such as “We are experiencing a network issue with a hypervisor on this cloud.” Most of my tickets have been replied to with a hypervisor-based answer. I would expect that the VPS.NET development team would have addressed these frequent hypervisor problems, but they keep popping up. It feels like the same problems keep coming up and no long term solutions are ever implemented. When my customers audit these support tickets, they are just baffled with the explanations. They don’t know what hypervisor means and they shouldn’t have to!

Do you know what a hypervisor is? It is a piece of computer software used to manage virtual machines.

On one particular instance, I opened a support ticket with VPS.NET where I explained what kind of connectivity issues my customer was experiencing with their service. I also asked several questions regarding network usage and limits. The ticket was immediately escalated to a Level 2 Tech. The Level 2 Tech then replied with “Please create separate tickets for every your requests.” I reported this poor service to a manager. Another Level 2 Tech promptly replied in my ticket with “there was DDoS attack to our DataCentre.” The first technician was clueless and simply didn’t want to spend time answering my questions. The second technician was probably told to tell the truth by the manager that I complained to about poor customer service.

I am hoping for better this year, but 2013 is already off to a rocky start with VPS.NET

I will not be recommending VPS.NET to any more of my customers until the level of service improves dramatically.

Splitting excess decimals from a number with PHP

Posted in PHP on September 9th, 2012 by Comments Off

Assume you have a number such as 5.2532 and you need to split that in to two numbers where the first number goes two two decimal places and the second number is the remainder. With the example number of 5.2532, the expected output would be 5.25 for number one and 0.0032 for number two. There is no PHP function that will let you do this by itself, but this can be achieved by combining a couple different functions without getting overly complicated.

At first, one might think that the best approach is to just convert the number to a string and use substr() to split it, but that is not a good approach if the input number can be anything and you don’t know exactly how long it will be, etc.

My solution was the following:

$input_number = 5.2532
$number_one = number_format(floor($input_number * 100) / 100, 2);
$number_two = $input_number – $number_one;

This method works for any input number. Observe the output for the following numbers.

input = 5.2532
number one = 5.25
number two = 0.0032

input = 3.1235
number one = 3.12
number two = 0.0035

input = 4321.123646521
number one = 4321.12
number two = 0.003646521

Hopefully this comes in handy for someone trying to tackle a similar problem. The logic can easily be adjusted for the first number to hold any number of decimals by just changing the second argument for the number_format function to the number of desired decimal places.

How to fix corrupt SQLite3 database

Posted in SQL, SQLite3 on August 5th, 2012 by Comments Off

SQLite3 databases can get corrupted fairly easily. It can be caused by a range of things, but probably the most common scenarios are hardware failure, power failure, or just hard reboots. An SQLite3 database gets corrupted when an application is performing tasks on the database and the server, power, or hardware fails and the database operations are cut off.

If a database is corrupted, you may be getting the following error when selecting, inserting, or doing various other things on the database.

database disk image is malformed

If you think that you may have a corrupted database, perform a quick check and see if that is the case.

sqlite3 yourdbname.sqlite
sqlite> PRAGMA integrity_check;

If the command returns anything else than “ok”, you may have a corrupted database.

The best solution for a corrupted sqlite3 database that I have been able to figure out is simple yet effective: Dump and Restore

First, make sure nothing is using or connected to the database. Then create a copy of your existing database.

cp yourdbname.sqlite yourdbname.sqlite.bk

Second, dump the contents of your existing database.

sqlite3 yourdbname.sqlite
sqlite> .mode insert
sqlite> .output yourdbname_dump.sql
sqlite> .dump

Third, move your original database out of the way, start a new one, and import the dump file.

mv yourdbname.sqlite yourdbname.sqlite.original
sqlite3 yourdbname.sqlite
sqlite> .read yourdbname_dump.sql

You should now have a backup of the original database, the original database with a different filename, and a brand new database with the data from your original database. The last step is to connect to the database and run the integrity check again and confirm everything checks out.

sqlite3 yourdbname.sqlite
sqlite> PRAGMA integrity_check;

The integity_check should return “ok” and you should be able to start using the database again.

Saving Forms for Later with LocalStorage

Posted in HTML5, Javascript on July 19th, 2012 by Comments Off

I came across a project recently where I was asked that when a user initially comes to a form — to store the values entered into the form, and upon the user’s return — prompt the user if they would like to refill the values of the form from when they last left. Previously, I most likely would have created some sort of duplicate table for unsaved versions of a form, or applied a status to an entry, and used AJAX to sync the forms. Now-a-days there’s this nifty little thing called HTML5 and LocalStorage, so, having a recent stint on relying on Javascript a lot lately, I decided this would be a really easy implementation. Read how after the jump. read more »

How to install Mumble-Server 1.2.3 on Debian Squeeze

Posted in Mumble on July 13th, 2012 by Comments Off

I installed the “mumble-server” package via “apt-get” and I did not want to change my setup. I wanted the package to be managed by apt-get organizational purposes, but at the time of writing, the mumble-server 1.2.3 version is not available in Debian Squeeze.

The solution was to add the Debian Wheezy sources to the sources list on my server by doing the following.

1. Open the sources list for editing.

nano /etc/apt/sources.list

2. Paste the following lines at the bottom of the sources list.

###### Debian Wheezy
deb-src http://ftp.us.debian.org/debian/ wheezy main
3. Update apt-get with the new sources.
apt-get update
4. Install mumble-server 1.2.3
apt-get install mumble-server
Note that if you already have mumble-server version 1.2.2 (or earlier) installed, you should backup your configuration file with the following command.
mv /etc/mumble-server.ini /etc/mumble-server.ini.bk
Once you have upgraded to version 1.2.3, you should edit the mumble-server.ini and put in your settings from your backed up ini file.

Mysterious Zeroc-Ice errors when working with Mumble

Posted in Mumble, PHP on July 11th, 2012 by Comments Off

I upgraded some Mumble servers to version 1.2.3 and when I visited the control panel that I was using to manage the servers, I was greeted with some mysterious Ice errors… mainly the following two.

  1. Fatal error: Uncaught Ice_UnknownLocalException ../../include/Ice/BasicStream.h:362: Ice::NegativeSizeException: protocol error: negative size for sequence, dictionary
  2. Fatal error: Uncaught Ice_UnknownLocalException ../../include/Ice/BasicStream.h:551: Ice::UnmarshalOutOfBoundsException: protocol error: out of bounds during unmarshaling

The error messages themselves are absolute gibberish to me and don’t provide any useful hints as to what may be wrong. After some google searches and tinkering on the server, I figured out that the slice definition for Mumble had changed from version 1.2.2 to 1.2.3, so I updated the slice for Mumble on my web server where I was using Ice to communicate with the Mumble servers.

My “Mumble.ice” file was being stored in a directory called “/usr/share/slice/” Once I had dropped the new Mumble.ice file in place, I went to restart Apache. It didn’t work and the web server did not come back online. I checked the Apache log to find the following error.

[Wed Jul 11 13:53:07 2012] [notice] caught SIGTERM, shutting down
/usr/share/slice/Murmur.ice:9: error: Can’t open include file “Ice/SliceChecksumDict.ice”
#include <Ice/SliceChecksumDict.ice>
1 error in preprocessor.
PHP Fatal error: Unable to start ice module in Unknown on line 0

The new Mumble.ice file contains an include command at the top “#include <Ice/SliceChecksumDict.ice>” The “Ice” folder that it tries to include from was not in my include/class path and I didn’t feel like tinkering with settings any longer, so I just changed the include statement to point directly to the “SliceChecksumDict.ice” file, which on my system was located in “/usr/share/Ice-3.3.1/slice/Ice/SliceChecksumDict.ice”

After changing the include statement in the new Mumble.ice file to read “#include </usr/share/Ice-3.3.1/slice/Ice/SliceChecksumDict.ice>”, everything started working. Apache started up nicely and my earlier Fatal errors were gone thanks to the updated slice definition.

I hope this helps somebody else figure out their problem.

Instant setup Mumble VoIP server hosting for free

Posted in Business & Development, Case Studies, Kohana Framework, Mumble, PHP, WHMCS on July 6th, 2012 by Comments Off

Over the last six months, I have been a part of the myMumble task force as the lead developer and infrastructure architect. We quietly launched the website on July 3rd and then made it official on July 5th by announcing the release through different media channels. The official “press release” is published on the myMumble website.

Free Mumble Server Provider

myMumble is a subsidiary of NationVoice Communications, the large VoIP communications leader. myMumble is not just another Mumble server provider. While other providers offer free trial servers, myMumble provides free life time five slot Mumble servers. I think that this will make a dent in the Mumble server hosting business and force the industry to adapt.

Anyway, enough of nonsense and hype.

The primary goal for me was to streamline the way that the myMumble business is operated and managed. Since it is a hosting business, WHMCS was obviously in my thoughts since the beginning. The core of the myMumble website is powered by WHMCS, but the landing page and some of the other secondary pages are built with the Kohana Framework.

One of the most important requirements for myMumble was to only have one username and password that the customers have to remember. It was also important that there was only one “panel” or “secure area” where the customer has to log in to. I did not want to use some hardly customizable third-party solution as the “control panel” for the Mumble servers, so I built my own from scratch as a module for WHMCS. It integration was quite simple and it fits well within the website.

Developing the code that actually communicated with the Mumble servers was simple. Mumble has reasonably good documentation for developers on their Wiki. The ICE module for PHP was the more secure and robust option for interfacing with Mumble servers, so I chose to use that for the module. I had never worked with the ICE extensions before, so I had an exciting time experimenting and learning with it. While the Mumble ICE class has some documentation, it was not that robust, so I had to do a lot of “guess and check” development.

For the WHMCS module, I had to build a completely custom provisioning routine for Mumbles since they required a more intense and product specific allocation and deployment logic that WHMCS did not support out of the box.

We have some other cool new stuff in the pipeline with myMumble. I hope to post some tech reviews about it in the coming weeks.

WHMCS not marking invoices as paid when paying with Paypal

Posted in PayPal, PHP, WHMCS on July 3rd, 2012 by 1 Comment

In a recent project for which I did all the custom development and systems integrations, I stumbled across a problem where WHMCS was not marking invoices as paid when a user paid via PayPal and returned to the website after paying. The invoice screen was confusing and had no indication of the payment that the user had just made.

First I thought that it was because PayPal was slow to send the IPN notification, but after waiting for some time and looking at logs, it turned out that the IPN notification had been received almost instantaneously, but the invoice was still marked as unpaid.

The Problem

After some digging, I figured it out. The problem was the the PayPal account had a primary email account and several aliases. An alias was being used for the project. When PayPal sent the IPN notification, it marked the receiver as the primary email for the account. This confused WHMCS because it was not the email that the system was configured with.

The Solution

In order to fix the issue, you have to put both the alias and the primary email in the PayPal configuration within WHMCS. Under “Setup > Payments > Payment Gateways” set your PayPal Email as “[email protected],[email protected]

Now when a user goes to pay, they will send their payment to “[email protected]” but WHMCS will now recognize the IPN notification when it comes over with the recipient email address as “[email protected]

Querying the database from a TWIG extension in Symfony 2

Posted in PHP, Symfony on June 1st, 2012 by Comments Off

Creating a TWIG extension in Symfony 2 is easy. Sometimes you need to execute database queries from a TWIG extension, but in order to do so, you have to tell Symfony to pass the Doctrine entity_manager as a parameter to the TWIG extension.

First, add a service record to your application config.yml file along with some configuration parameters.

app/config/config.yml

services:
    my.twig.extension:
        class: CodeRelic\SampleBundle\Extension\CodeRelicTwigExtension
        tags:
            -  { name: twig.extension }
        arguments:
            em: "@doctrine.orm.entity_manager"

The above service definition is quite self forward. It tells Symfony where your extension lives and what arguments to pass to it. The twig.extension tag also let’s Symfony know that this service needs to be loaded as a TWIG extension.

The next step is to create the extension. Create a folder called “Extension” inside your bundle. In this example, the file is created in:

src/CodeRelic/SampleBundle/Extension/CodeRelicTwigExtension.php

<?php
 
namespace CodeRelic\SampleBundle\Extension;
 
class CodeRelicTwigExtension extends \Twig_Extension
{
    private $em;
    private $conn;
 
    public function __construct(\Doctrine\ORM\EntityManager $em) {
        $this->em = $em;
        $this->conn = $em->getConnection();
    }
 
    public function getFunctions()
    {
        return array(
            'categories' => new \Twig_Function_Method($this, 'getCategories'),
        );
    }
 
    public function getCategories()
    {
        $sql = "SELECT * FROM categories ORDER BY name";
        return $this->conn->fetchAll($sql);
    }
 
    public function getName()
    {
        return 'code_relic_twig_extension';
    }
}

This is all you should have to do in order to get your TWIG extension working and to be able to use the database from it. In the above code sample, we have defined a TWIG function called “categories,” so in your TWIG layout files, you can now loop through all the categories in your database. See example below.

<ul>
{% for category in categories() %}
    <li>{{ category.name }}</li>
{% endfor %}
</ul>

Optimize Sprites for Retina Display

Posted in CSS, HTML5 on May 23rd, 2012 by 1 Comment

With newer technologies like the retina display popping up, being able to take advantage of the retina display is a huge advantage.  The retina display is currently supported by iOS, however there are rumors the retina display will be coming to Apple’s MacBook line.   That means the high resolution people are building for applications, is soon coming to the web.  Or, for that matter, this would be a really good starting place for making web applications use the retina display.

If you’re unfamilliar with spritesheets, and how they can help your site, you should look into it.  Otherwise, I’m going to show you how you can optimize your sprites very easily with a vector Photoshop file, and a few lines of code.
read more »

WHMCS.com was hacked and customer info leaked

Posted in Miscallaneous, WHMCS on May 22nd, 2012 by Comments Off

The hacktivist group, UGNazi, took down WHMCS.com on Monday. The hackers gained access to the main WHMCS server by impersonating WHMCS staff and persuading the webhost, Hostgator, to hand over login credentials to the account. Once the hackers were in, they took down the website and made it redirect to the hacker group’s website. After a couple hours, WHMCS was able to regain control and restore their website and service. read more »

Amazon Web Services and Kohana

Posted in Kohana Framework, PHP on May 20th, 2012 by 1 Comment

For anybody not in the know, Amazon has a set of really cool hosting services called Amazon Web Services that they sell which are ALL accessible via a robust API. Are you building an application that may have traffic spikes? then you can use the aws api to spin up a couple of backup servers, and then shut them back down after the spike has abated (amazon charges by usage). This post isn’t going to be about how cool aws is (for more info go here). What I’m here to talk about is how to use any of the myriad aws services in your Kohana project. What we’re going to do is download the PHP SDK that Amazon provides for interacting with their services and package it up as a Kohana module that you can include in any of your projects. read more »

Remove payment options for free products in WHMCS 5

Posted in WHMCS on May 18th, 2012 by 3 Comments

WHMCS by default requires that every order has a payment type associated with it regardless whether the order is free or not. This means that the default functionality of WHMCS is to display the payment options on the checkout form every time. This can be very confusing for a customer that expects a free product, but then is required to select a payment type.

On a current project that I am a part of, I had to remove the payment options for free checkouts. It turned out to be quite simple.

The Concept

The idea is to put a <div> around the payment options and set style=”display:none;” on the div if the order total is zero.

The Solution

In my project, I was using the Web20cart theme for the checkout pages. The concept will work for any of the cart themes that come with WHMCS and probably with any custom theme as well.

In templates/orderforms/web20cart/viewcart.tpl, find the code block that looks like this:

<h2>{$LANG.orderpaymentmethod}</h2>
  <div class="cartbox">{foreach key=num item=gateway from=$gateways}
    <label><input type="radio" name="paymentmethod" value="{$gateway.sysname}" onclick="{if $gateway.type eq "CC"}showCCForm(){else}hideCCForm(){/if}"{if $selectedgateway eq $gateway.sysname} checked{/if} /> {$gateway.name}</label>
    {/foreach}</div>

Put the codeblock inside a <div> that has a trigger for the style=”display:none;” attribute, so the payment options are hidden if the order total is zero dollars.

<div {if intval(substr($total,1,-4)) == 0}style="display:none;"{/if}>
  <h2>{$LANG.orderpaymentmethod}</h2>
  <div class="cartbox">{foreach key=num item=gateway from=$gateways}
    <label><input type="radio" name="paymentmethod" value="{$gateway.sysname}" onclick="{if $gateway.type eq "CC"}showCCForm(){else}hideCCForm(){/if}"{if $selectedgateway eq $gateway.sysname} checked{/if} /> {$gateway.name}</label>
    {/foreach}</div>
</div>

How to clear cache for Adobe Flash 11.x

Posted in Flash on May 15th, 2012 by 1 Comment

Clearing cache for Adobe Flash is easy. Just follow the steps below.

  1. Right click any flash application (a Youtube video for example) and click the “Global Settings” option
  2. Click the “Advanced” tab and click the “Delete All” button
  3. Choose the data that you want to delete and click the “Delete Data” button