Markus Tenghamn

Programmer and Entrepreneur

Laravel and keeping my bitcoin bot running forever

23rd of January, 2016

So I was trying to figure out how to keep a script running forever as I want to constantly get social media updates and feeds from bitcoin exchanges when I use my bot to trade. Previously I would have done this with a bash script that would check for a tmp file that would be generated when the script was running and removed when it stopped, The script would be accessible as a console command in laraval making it easy to run. However, this could sometimes fail as well. I figured there must be a better way to achieve what I want to do.

I headed over to Reddit and posted my question where I have gotten a lot of help before and got a really useful answer from mbdjd. I had overlocked the cron section of the Laravel documentation that mentions the withoutOverlapping() method which would basically start my script whenever it stopped and keep it running at all times.

Bash script for new Laravel install on Ubuntu 14

23rd of January, 2016

The following is a simple script that I have used to set permissions on development builds for Laravel, it usually fixes permission issues and gets me up and running quickly. You can put it into a .sh file to run all the commands or simply copy and paste. I also have this running with git as a post-receive hook that will copy the master branch to a testing server.

mkdir bootstrap/cache/;
mkdir storage/framework/cache;
mkdir storage/framework/views;
mkdir storage/framework/sessions;
sudo chown -Rf $USER:www-data .;
sudo chmod -R o+w storage;
sudo chmod -R o+w bootstrap/cache;
sudo chown -Rf www-data:www-data bootstrap/cache;
sudo chown -Rf www-data:www-data storage;
php artisan clear-compiled;
php artisan config:clear;
php artisan optimize;
php artisan migrate;
php artisan db:seed;
sudo apt-get install npm;
sudo apt-get install node;
npm install gulp; 
npm install laravel-elixir; 
sudo gulp;

Bitcoin bot

22nd of January, 2016

So tonight I took a little break to work on an idea that I have had for a while. Initially I wanted to look at social media, analyze the text to try to put a positive or negative number which would hopefully give an indication on where the stock price would go. Now tracking stocks can be complicated due to delays in APIs and things like that and you would also need to decide on which stocks to pick. I guess this turned me off a bit as I wanted to make something quick and simple that would give me results. That gave me the idea of trying something different like bitcoin (also litecoin and dogecoin because why not?). What if I could use my bot to predict when the price of bitcoin would go up or down, a simple bitcoin bot? I could very easily get several indicators for my bot and then tell it when to buy or sell. Tonight I got started on the bot which currently gets a live feed of every single tweet metioning bitcoin as a live feed, check it out 😀

Bitcoin twitter live feed

Bitcoin twitter live feed

I can now build a dictionary for positive and negative words which I can then compare and tweak to try to match the price. I also thought of two more indicators while I worked on this which are the amount of tweets (popularity) and also the amount of transactions (buys and sells, aka demand). Hopefully this project can turn into something useful and be a start for a similar bot that predicts stock prices.

Why Online Advertising Should Listen To The User

20th of January, 2016

Online advertising is a very one sided market with all emphasis being put on the companies that need a quick way to reach users but almost no thought is put on the user. Of course it is not the companies responsibility in mind, unless they manually put their adverts on websites, it is up to the ad networks. There are many ad networks out there, the biggest being Google Adwords. Now the only way for a user to give feedback about an ad is to search through Google’s help pages which is nowhere near easy.

So what’s the problem with online advertising?

Sure, online advertising has been around for a long time, over 30 years if wikipedia is correct. Eventually all the ads became too much for users, especially with javascript and flash animations that sometimes included sound. Oh and don’t even get me started on malware and viruses that have been spread through online ads. This abuse by companies has led users to create and use adblockers such as Adblock Plus which even I use with the exception of websites that I trust and go to often. This leads to big losses for companies that earn money through advertising which is unfortunate, I personally feel bad when blocking ads on some sites but I don’t want it to ruin my experience and I do not want to risk getting malware if I can prevent it.

So how do we solve this problem?

Ad networks need to start listening to the user more which would be very easy to do and it would probably give companies a better return. Users can help companies advertise in a way that is fair to the user and that won’t annoy them. A rating system could be implemented for ads which would be based on certain criteria. You could also have different categories to allow for different kinds of ads. I’m sure Google could even get more registered users as a registered account might be needed to set the rating of ads you want to see. For example I might choose to only see ads that are static images and hide anything with animations or sounds. This creates a better experience for myself, I might even like the ads being presented, I will also support the sites that I visit and the companies that do the advertising are happy that they can reach a wider audience. With the rating system in place the companies could also get great feedback on what users love and hate and some users might even give useful ideas on how to improve conversion rates on ads. Users could have some kind of point system to reward them depending on how active and accurate they are in their ratings, similar to how the rating system on Stack Overflow works.

Time to change the website a bit

16th of January, 2016

About 6 months ago I accepted a great job at Key Solutions here in Västerås, Sweden where I live which has kept me pretty busy lately. I don’t have time to write as much as I did before and and the time has also given me time to think about what I really want to publish here. The blog will be more personal from now on and less promotional. I want to share random thoughts and ideas that I have during the day which might result in some shorter posts. I also want to share my knowledge and solutions and perhaps contribute a bit to open source libraries when I get the chance. As you may have noticed my blog has a much cleaner and simpler look which I love, it looked messy in the past. Anyways to get started with the new blog let’s take a look at some of my interesting projects which are free to use and open sourced.

You have the iOS app that I created for my blog which simply reads my rss feed and publishes it in the app. It is available on the app store, simply search for “Markus Tenghamn” and you will find it. The complete source code can be found on github here:

Oh and feel free to follow me on Github here and ping me if you want me to take a look at an interesting project.

Recently I also made my first real contribution to a Github project, it’s not much but if anyone needs Swedish localization for carbon on laravel you will find it here

Anyways, currently I am messing around with nodejs, redis and beanstalk to get a laravel installation working, I’m sure I will have something to say about it soon so stay tuned for more interesting posts.

Anveto Push Notifications

Anveto Push Notifications For WordPress

31st of March, 2015

My latest plugin made via Anveto stores tokens from apps that can then be used to send push notifications. My idea was to create this plugin and store tokens in order to add more functions to it later such as exporting the tokens to csv format or sending push notifications directly from wordpress whenever a new post is added on my blog.

You can find the plugin here

UberChat Wordpress Plugin

UberChat for WordPress with Windows Client [Review] [Video]

30th of March, 2015

Today I will be reviewing UberChat for WordPress with Windows Client which is a really nice live chat support plugin. You can find the plugin on CodeCanyon by following this link.

You can also watch my video review on Youtube by clicking here.

Let’s get started! The plugin comes with a lot of clear documentation, however the first step is pretty easy. We need to upload our plugin either by using an FTP program like Filezilla or by simply using the standard add plugin form on your WordPress site. Then activate the plugin and make sure you don’t see any errors.

When this is done your should see the UberChat menu on the left hand side inside your WordPress installation. Take a look at the settings page to make sure everything looks correct. For example you may want to change the email that will be used or the categories/pages where your chat box will show. If everything looks good simply head over to your Dashboard, in the top right corner you will see a button called “Go Online”. Once this is clicked you will go live. This was the only problem I had with the plugin, when online the “Go offline” button has an animated gif which makes it looks like it is trying to load something. After a short time I realized that it was simply something that indicated that I was online. Perhaps there is a better way of showing that the user is online.

Once you are active you can test the chat by going to another tab or opening a different browser. The addon seems to use gravatars for users profile pictures. While you are active in the dashboard you will also see that you can see what visitors are currently visiting the site and where they are from. One of the unique things with this addon is the ability to invite users to chat.

If you look on the left side you will also see that the plugin allows you to see chat logs of previous sessions and form submissions for when the live chat is inactive. You can also setup canned responses. These automated responses can be used while in the chat to send standard messages such as a “welcome, how can I help you?” when the user first enters the chat or answers to common problems that users may have such as finding their way to the checkout page.

This plugin also includes a windows chat application which will connect to your WordPress installation and allow you to chat with users without having to have a browser open. In order to set this up you will need the API-Key from your UberChat settings page inside your WordPress installation. You will also need to provide a username and password for the user who will be chatting to other users. To begin setup navigate to the Windows Client folder and find the .exe file to begin setup. The setup was easy and pretty self explanatory. Once that is done you should find UberChat in your windows start menu. When opened the first time you will need to enter your CodeCanyon username and purchase code which you can get from CodeCanyon in the downloads section of your profile. Once this is done you will be promted to enter the API key from your UberChat settings area and the login information of the user who should act as the support operator. You can also select from settings such as language, theme and notification sounds. Once logged in you will see the same layout as you did in your dashboard. When a user begins a chat it will pop up in your windows application and you can begin chatting.

Need help installing this plugin? Experts at Anveto can install and configure this plugin for you quickly, please click here to read more and order.

Overall I think the plugin is really great. It seems to run smoother and faster than other live chat support scripts and has all of the basic features. I hope more features will be added in the future as the author of the plugin has created many similar scripts and seems to be an active developer.


WHMCS Licensing Addon How To

How to configure and setup WHMCS Licensing Addon [Review] [How to]

27th of March, 2015

Almost 3 years ago I wrote an article regarding WHMCS Licensing Addon and how to set it up. Back then I was new to WHMCS and not as good at PHP as I am today. Due to the articles popularity I have decided to revisit this topic and make a new, more detailed post on how to get going with the addon. I will link to this article in the old guides as this article should be more relevant and is made for WHMCS version 5.3.12 and Licensing Addon version 3.0. I have also made an easy to follow video to go along with this guide which you will find here on YouTube.

If you need help integrating the Licensing Addon to a php script this is something we offer at Anveto, click here to read more and order!


As for my review, I can say that this has been the easiest and most secure way to protect my php scripts. Sure it is not fool proof but it is very good compared to other free alternatives. I also like the use of a local key to keep the script from having to check with the server every time it is used, instead it will make one check ever 15 days or so, you can of course change how often the check is done. Inside of your WHMCS installation you will also see when the last check was made, where the script is being used, and what the status is. WHMCS itself allows you to automatically suspend licenses if an invoice is overdue which is very convenient and clients can see the status of their services/licenses inside the client area if needed.

Configure and Setup

Let’s get to the configuration and setup which is now easier than ever as the licensing addon is included when you download the latest version of WHMCS. You will of course need to go to Setup->Addon Modules and activate the licensing addon making sure to set the Access Control to Administrator or whichever group you would like to have access to it. Now that that is taken care of you should see the licensing module when creating a product. So either create a new product under Setup->Products/Services or edit an existing one. Then in the tabbed menus navigate to Module Settings. Click the dropdown and select Licensing as the Module Name. This will present you with several options, the first being key length. You can set the key length to any number, I used 35 in my example as I find it to be a good length. If you plan on having a few licenses then a short length is fine, however if you plan on issuing millions of licenses you may want to consider a key length closer to 35 as I have done. I checked the box to allow reissue, this basically means that clients can move the script to a new domain or path without having to open a support ticket and have me do it manually. Next is the Key Prefix which can be good if you are trying to identify which product a license is for, perhaps wordpressplugin1- is a good identifier, pick anything. Now for the secret key I simply generated a password which is unique for this product, you can enter any string here but I would recommend using some form of password generator. There are a few other options here but I am not going to cover it in this guide.

Now we can navigate to the links tab, copy the link to the product and perform an order to see if everything works and also to get our license key that we want to test with. After the order has been made on your test account and after accepting the order in the admin area, you should find your license key in the test accounts client area under services. Keep this as we will need it later in this guide.

Next we need to find the code that needs to be included in our script, the license check code. WHMCS also includes this in the latest releases and we can find it using an FTP client by navigating from the WHMCS root to modules->servers->licensing->check_sample_code.php. We need to copy this code and then head over to our PHP script which we want to add the license to. Now I don’t want to clutter things up so I will be making a new project, however you could create the same files and later integrate them into your script.

To begin with I will create a file called license.php, this code will hold all the code that I just copied from the example file. Once we have pasted the code we can make some small modifcations right after “function yourprefix123_check_license”. You can change the $whmcsurl to your WHMCS installation url making sure to keep the trailing slash. You also need to add the $licensing_secret_key which we added to our product earlier. If you don’t remember this step please see my video as this clearly shows where to find this key. You can also modify the $localkeydays and $allowcheckfaildays if needed but I think the default values are pretty good to use. Now that is all we need to edit inside that function, the rest of the code is what does the actual checking of the license which we never need to modify. If you scroll down to the bottom where this function ends you should see an example $licensekey and $localkey. We won’t modify these right away as I am going to use a text file for this example, however you could input your licensekey here and just use this file, however without storing a local key in a file or database then you will be checking that the license is valid on every page load which is not good.

Next, we will create a file called addlicense.php which will be used to store our license key inside a text file. This will be a basic form which will write to our text file when the form is submitted. At this time we can also go ahead and create the license.txt file which will hold our license and local keys once everything works.

$success = false;
if (isset($_POST['license'])) {
    $license = $_POST['license'];
    $base = __DIR__;
    $textfile = fopen($base."/license.txt", "w") or die("Unable to open file!");
    $contents = $license."\n";
    fwrite($textfile, $contents);
    $success = true;
    <title>License Test</title>
<div class="wrapper">
    <div class="form">
        if ($success) {
            <p>License added!</p>
        } else {
        <form method="post" action="">
            Enter your license <input name="license">
            <input type="submit" value="Add">
        <?php } ?>

This is my addlicense.php file. Going from top to button we begin by setting a bool called $success which is always false unless a license key has been submitted. We don’t do any validation here as it is an example but when using this in a real script you probably want to make sure that at least the length matches to make sure your user found their key. The $_POST[‘license’] is the text field from the form and if it is set, if the form has been submitted, we try to write whatever was in this field to our textfile, license.txt. $base gets our current directory so that we can access the text file in the same directory as the addlicense.php file. We then open our textfile, write our license key to it with a line break and then close the file. If we were unable to open the textfile then the script will stop and output “Unable to open file!”. If this happens you need to make sure that you added the text file and that you have set file permissions so that apache/web can write to your text file. Next we load the actual html for the page, if $success is true it means that the form was submitted and since we got this far then we know that the license was added and we say “License added!”. If not then the form has not been submitted and we show the form where the user can enter the license. In a real world example you would probably check if the license has been added and if it has been validated already and display this information to the user. This form might also be added inside of an admin area or something like that. If you wanted to store the key using MySQL you would simply replace the text file writing at the top with your MySQL query, updating the license key in the database.

Now let’s head back to our license.php file where we pasted all that sample code. From the top, make sure you have removed the “exit;” as this will cause you to only see a white page when testing your code. Next we go down to our function, yourprefix123_check_license, which you can change to pretty much anything, I changed mine to say licensetest_check_license but you could call your function ketchup($licensekey, $localkey=”) if you wanted to.

Now scroll all the way to the bottom and find your $licensekey and $localkey. In this area you should see yourprefix123_check_license, rename this to the same thing as you did above. Now I make several changes to the code and I will go through it shortly. Below you will see how I have changed the code in the license.php file under the check license function which we just renamed.

// Get the license key and local key from storage
// These are typically stored either in flat files or an SQL database

$licensekey = "";
$localkey = "";
$base = __DIR__;
$handle = fopen($base."/license.txt", "r");
if ($handle) {
    $count = 0;
    while (($line = fgets($handle)) !== false) {
        // process the line read.
        if ($count == 0) {
            $licensekey = trim($line);
        } else if ($count == 1) {
            $localkey = trim($line);

} else {
    die("Could not read license file. Please contact support.");

echo $licensekey."<br/>";
echo $localkey."<br/>";

// Validate the license key information
$results = licensetest_check_license($licensekey, $localkey);

// Raw output of results for debugging purpose
echo '<textarea cols="100" rows="20">' . print_r($results, true) . '</textarea>';

// Interpret response
switch ($results['status']) {
    case "Active":
        // get new local key and save it somewhere
        $localkeydata = str_replace(' ','',preg_replace('/\s+/', ' ', $results['localkey']));
        $handle = fopen($base."/license.txt", "r");
        if ($handle) {
            $count = 0;
            while (($line = fgets($handle)) !== false) {
                // process the line read.
                if ($count == 0) {
                    $licensekey = trim($line);
            if (isset($results['localkey'])) {
                $textfile = fopen($base . "/license.txt", "w") or die("Unable to open file!");
                $contents = $licensekey . "\n" . $localkeydata . "\n";
                fwrite($textfile, $contents);
        } else {
            die("Could not read license file. Please contact support.");
    case "Invalid":
        die("License key is Invalid");
    case "Expired":
        die("License key is Expired");
    case "Suspended":
        die("License key is Suspended");
        die("Invalid Response");

Basically what we are doing is checking for a license key and local key and reading it from the text file. If the license is valid we store the new local key so that we don’t have to run the check again for another 15 days. Now there is a lot of code to go through here but we will go through it just like we did before, from top to bottom. So what I did first was to remove the example $licensekey and $localkey and leave these blank. If there is no key in the text file then the blank key will be checked and be returned as invalid. After these two variables we set our base directory with $base so that we now that text file we are reading is in the same directory. We then try to open the text file and read it line by line. Because of the way we store the licensekey and localkey we know that the first line is always the licensekey and the second line is always the localkey. If the license has never been checked the $localkey will remain blank, all this does is force the license check function to try to make a call to the license server (your WHMCS install). So once we are done reading the text file we close the $handle. I decided to echo my licensekey and localkey here so that I could see what was stored in my text file, you can should probably remove this echo and your textarea echo when running this on an actual script. Next we call our license function with $results = licensetest_check_license($licensekey, $localkey), remember that you may have changed the name of this to something else. After this i print out the returned $results in a textarea and then I proceed to the provided switch case which looks at the status key of the $results array. If this key is equal to “Active” we then know that the license was validated and that a localkey should have been returned if this was a remote check. One important thing here is to remove the spaces in the $results[‘localkey’] as it can mess things up if you are reading a text file line by line. However if the validation was done via the local key, as in no call was made to the license server, then there will be no local key returned. This is why I check to see if the $results[‘localkey’] is set further down so that I don’t overwrite an existing local key with a blank key. I also copied the earlier code and once again read the text file line by line to get our license key from storage once again. If the local key was returned in the results array I then proceed to write the license and local key to the text file.  You will see other cases in this switch case statement which I have not modified. In these other cases you may take some kind of action such as displaying an error message to the user saying that his invoice is unpaid and that he should contact support. Although please keep in mind that your clients users may also see the message so I would recommend showing a general error message as to not embarrass your client with a personal message.

Thanks for reading the guide, I hope it helps. Feel free to leave and comments, questions or suggestions in the comments below! Remember, if you need help integrating the Licensing Addon to a php script this is something we offer at Anveto, click here to read more and order!

PHP Flat Visual Chat

PHP Flat Visual Chat [Review] [Video]

25th of March, 2015

Today I will be reviewing PHP Flat Visual Chat from CodeCanyon. This is part of a series of reviews which I will do of some of the most popular support chat scripts and plugins available on CodeCanyon. I will be using the standalone PHP script however there is also a WordPress Plugin available here. If interested in my video review please visit this link to head over and watch it on YouTube.

We will begin with the installation. The provided documentation is pretty clear and the installation is simple, simply drag the included folder to your website root. This folder will be where you access your admin panel.

Drag Folder

Once that’s done we will need to edit the config.php file and add our database settings. If you don’t have a database for this script you will need to create a new one.

Configure Database Settings

Next step is to first add the root url to the flat-visual-chat.js file and then include the javascript code in the footer of your page. Usually you will have a footer.php file or something similar as I do in my wordpress theme. If you have a standard html site you will have to add this javascript code to the bottom of every page that you want to show the chat on. If you need help with script installations you can have Anveto install this script for $30, click here to order. I added the javascript right next to my Anveto and Google tracking code which was already on the page.

Add Root Url

Now you should be ready to try to see if it works. Navigate to the folder that you uploaded and you should see a promt to create the admin account. Then login with the details you just entered and you will be presented with your home page along with an overlay which is your admin control panel. You can test that this works by opening another browser, I used safari. I can type in a name and start chatting right away. The chat shows up at the bottom of the screen and a notification is heard when I receive a message.

Begin Chat

Now what really sets this script apart from the others is that you can help the user navigate to different pages on your website. This is great if you need to show a user where to find something in the knowledgebase or perhaps where the user needs to go to begin the order process for a specific product or item.

Show User Item

I would greatly recommend this script to any person or business who needs to run any kind of chat support on their website. The chat is easy to use for both client and admin and I am impressed by the helpful features which I have not seen in other chat scripts that I have used in the past. Hope you liked the review, please leave any comments, suggestions and feedback below. I will work on getting more reviews up in the future. Oh and please do let me know if there is something which you would like to see reviewed!