Heroku and MySQLi – Round 3

As of a few minutes ago, Heroku now natively supports PHP, MySQLi and some other enterprise level PHP functionality.  This is great news.

https://devcenter.heroku.com/articles/getting-started-with-php

Validated with:

<?
if (function_exists('mysqli_connect')) {
 //mysqli is installed
 echo 'it works';
}
else{
die('bad news');
}
?>
Posted in Heroku, php

Keep Heroku App from Sleeping

1. Add Scheduler App to Heroku (heroku addons:add scheduler)

2. Create a worker file that pings your app URL

Ex:

<?
$url = ‘YOUR HEROKU APP URL’;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode) {
echo “I am working”;}

else {echo “I am sleeping”;}

3. Create a scheduler job that runs every 10 minutes to request the main page of the app. (bin/php /app/www/scheduler.php)

Now every 10 minutes, heroku scheduler will ping your site so it doesn’t go to sleep, and you can still use the single web dyno to run / host static files.

Log Example:

2014-04-08T19:35:15.617772+00:00 heroku[router]: at=info method=HEAD path=/ host=salty-earth-3634.herokuapp.com request_id=f63916ac-0e4c-4b72-b30a-55088bd610b6 fwd="54.211.207.193" dyno=web.1 connect=1ms service=8ms status=200 bytes=167
2014-04-08T19:35:15.695511+00:00 app[scheduler.6695]: I am working
2014-04-08T19:35:15.375210+00:00 heroku[scheduler.6695]: State changed from starting to up
2014-04-08T19:35:16.306243+00:00 app[web.1]: 10.185.139.223 - - [08/Apr/2014:19:35:15 +0000] "HEAD / HTTP/1.1" 200 -
2014-04-08T19:35:16.948716+00:00 heroku[scheduler.6695]: Process exited with status 0
2014-04-08T19:35:16.960716+00:00 heroku[scheduler.6695]: State changed from up to complete
Posted in Heroku

Facebook Login Shell for PHP

Just posted a project on Github that is a php login shell for Facebook.  Its something wrote to be simple, single sign on for apps, and hope others find it useful as well.

 

Project can be found here: https://github.com/travstoll/php_login

 

  1. Create Database using using create_db.sql -This will create a database fb_login with a single table, users. Here the facebook info for the user will be stored including, id, picture, email, ect.
  2. Create the facebook app (1) -https://developers.facebook.com/apps/ -Click ‘Create New App’ (2) -Enter a Display Name and Namespace -Choose Category -Create App

    -Add Cavas and a website and reference the domain in the app settings (3)

  3. Set Credentials in app
    • In the /app folder set the db credentials in /inc/db_con.php
    • In the /app folder set the appId, secret, and redirect_url to the /app index in the index.php file.
  1. Thats it, when users login, they will see a request to authorize app, authrize it and it will be logged in your table and checked at every login. (4)

Notes:

If you receive error: ‘Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App’s settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App’s domains.’ Add the domain you are using to the app config.

Can’t use localhost anymore as an app domain. A workaround is to edit the /private/etc/hosts file and add a domain Ex: 127.0.0.1 dev.thestoll.com to it. This puts dev.thestoll.com to loopback to local.

Posted in php

What is your business doing to prepare for the Internet of Things?

Great article from PTC this morning.

What is your business doing to prepare for the #IoT? Successful manufacturers enable these 6 capabilities → http://ptc.co/uhlKR 

Posted in Customer Experience, IT