Category Archives: PHP

Anything related to PHP and any Frameworks associated.

WAMP Server and PHP ZeroMQ Extension Installation

I spend a lot of hours to do this , so I dont forget how it all works and all. ZeroMQ is a PHP extension that allows PHP to do Websockets for live communication. When you do your development specially on a Windows platform , Wamp is just my go to program to install to do some easy PHP development.

Follow these step:

  1. After downloading and installing WAMP Server.
  2. Download the DLL extension https://pecl.php.net/package/zmq . Make sure you download the version for the PHP you are using. There is some stuff you need to consider before attempting this and making sure you get the right one.
    • Thread Safety or Non-thread Safety. Make sure you choose the one appropriate with your PHP installation. Check phpinfo() to see whether its TS or Non-TS.
    • Also check you have the Visual C++ Redistributable installed. Again see the version of VC++ Redistributable you need in phpinfo() VC11 is usually version 2012.
    • Finally check whether you are running x86(32bit) or 64 bit version of WAMP.
  3. Then move php_zmq.dll in your EXT folder of your PHP directory.
  4. Importantly either/both copy libzmq.dll in your root PHP folder or APACHE folder. This is the one Im having issues with.
  5. When you restart WAMP and you dont see any changes happening. Check for the PHP_LOG if there is any error. Usually there will be but if not. You are good to go. Also RESTART WINDOWS. And double check in your phpinfo() if the extension has been loaded or not.
  6. And you should be done!

IMPORTANT NOTE AND TIPS:

Sometimes or most likely WAMP will complain about PHP folder is in your PATH environment variables. We definitely want PHP on there and Composer need this path. You can ignore the error by going to WAMP icon right click on it and go to WAMP settings and check “Do not very path”.

Please be aware this might be an issue with WAMP. WAMP allows us to change version of PHP to use. So know that when you are changing PHP version. Better to remove PHP path from the environment variables and restarting before changing PHP version to prevent any issues.

Although Its weird that to use ZEROMQ we definitely need the PHP path there to save us time from typing the whole complete path PHP cli. Remember WAMP is just our development platform. You can probably get away from WAMP and use DOCKER instead but WAMP is just so easy. But that is just a topic for some other time.

Cheerios!

Eloquent helper functions, filters and mutators

I have been looking through the internet how I can make my coding more efficient specially when using Eloquent ORM. Eloquent returns a collection that can be filtered using various helper functions.

I would say how I can make my programming skills be more “functional” instead of the traditional for each loop. Check the link out for using helper functions once collection has been returned.

http://laraveldaily.com/10-less-known-but-awesome-laravel-collections-methods/ 

I will also add Accessors/Mutators basically when you set or access a field value , it will automatically returns a different format. For basic example, $users->firstname original value is “Sarah” if you used an accessor function defined in your model, you can automatically make the value apply any function such as strtolower(value) to make it return lowercase.

I find this link helpful: http://laravel-guide.readthedocs.io/en/latest/eloquent-mutators/#defining-a-mutator 

Love at first Laravel Eloquent

Its been a while since I posted been a month it seems?

Well I have been doing a lot of developing and I just love Laravel’s Eloquent component. When doing small web applications, you dont wanna go full Laravel on that stuff. You would wanna just go small like Lumen small, when I say Lumen like micro-framework Lumen. Laravel is a full blown framework, if you just want a small application you can never go wrong with a micro-framework, there are a lot out there. Im currently working on Slim 2 Framework although very old, I needed it to support really old PHP 5.2.

I have learned alot, on my first month on the job. Namely composer and Im using alot of package manager lately. NPM and bower front end development stuff. But anyways I would like to share you links on how to make ORM Eloquent and using 2 databases without Laravel altogether.

First is how to use Eloquent ORM on your own project follow this link: http://www.edzynda.com/use-laravels-eloquent-orm-outside-of-laravel/ 

Then how to use 2 database connections, this is really big if you are using SQL Server and MySql hand on hand you need to be able to switch between your eloquent database. Follow link: https://stackoverflow.com/questions/25371871/two-databases-in-eloquent-orm-without-laravel

Bootstrapping – Relative Path trailing slash / (PHP)

When developing a site with bootstrapping in mind, (by the way bootstrapping is a technique in web development when all request gets directed to one page that is usually index.php for example a request to page, http://domain.com/user , http://domain.com/profile/edit etc. is handled by index.php with the help of a mod_rewrite script in the root directory. And creates a slug url for SEO.) when this is done an issue will occur relating to relative path and pointing to static files in your site such as images, css and scripts especially . Imagine this scenario:
Examine the file structure

public_html/index.php
public_html/css/style.css
public_html/images/image1.jpg
css/root.css

When someone request a url from your site eg. “http://domain/user” and in the page your css points to “css/style.css”, your page will come out alright but when they add a slash at the end “/” “http://domain/user/” like so, your browser will interpret the slash as a folder location to “user/” so if your path to your css is “css/style.css”, your browser will look for the file in “user/css/style.css” which in this case the folder doesnt exist and so your website will come out really messed up.

So remember to fix this when you are developing a site based on bootstrapping. You can fix this either by .mod_rewrite or simply via your PHP script by checking the trailing slash at the end from the REQUEST_URI variable.
Until next time.

PHP Header Function – Redirect – Exit

I was developing my site when something weird happened , mostly sessions get UNSET in the end of my php script, but when developing In the middle script a redirect function like the “header(‘location: http://mydomain/etc’);” I assumed once redirected the any script below it wont run anymore but I was wrong.

Then as soon as the header function has been called, the script below it ,has triggered as well while performing redirect. At first I didnt know what was wrong with it until I just unknowingly added EXIT; after the header function and everything works fine.

So for my reference ALWAYS REMEMBER TO PUT an exit function AFTER the redirect function so that there wont be any weird issues developing your site along the way. Especially when your developing using PHP.