General tips

Sandbox / Developer /

Composer memory allocation error

  • Written: 5 years ago
  • Category: Developer
  • Comments: 0
If you are in the PHP community and arn't using Composer, you are being left behind by its awesomeness. However Composer has some issues that its trying to solve as it grows. From time to time as Composer tries to work out your package dependancies it might run out of memory. This is rare, but can be annoying if you are in a hurry. Try running the following command to give PHP more memory to work with...
Sandbox / Developer / General tips /

How to enable PHP Opcache

Since PHP 5.5 Opcache is baked right in, however its disabled by default. If you're working on a shared host, then its pretty unlikely you'll be able to get this working, however if you, like me, just switched over to Digitalocean and are loving the new freedom you have to set up the server, you'll want to follow these quick tips. First you need to ssh into your server, i'll leave that up to you to figure out. Once inside you need to know where the file "opcache.so" file is situated. This file needs to be added to your 'php.ini' file and so to find it, we run the following command...
Sandbox / Developer /

Create your own jQuery (or raw JavaScript) events and trigger them whenever...

  • Written: 6 years ago
  • Category: Developer
  • Comments: 0
One of jQuery's less promoted attributes is that it allows us to bind and trigger our own custom events. Its a simple enough idea, but incredibly powerful! The reason the custom events are so powerful is that it means we can decouple our application, creating modules that only interact through the triggering of hooks/events. But what does that actually mean, well it means less long variable names to stop from accidental  or unintentional reuse;  smaller, more maintainable code; less time spent debugging; more time doing other fun stuff. To register your custom event you need something like the following...
Sandbox / Developer / General tips /

Auto include your debug functions through php.ini

You might not want to bloat your system with whatever debug functionality you need whilst its being developed. Instead you can add a line in your php.ini that will tell PHP to include a file from the local file system each time PHP runs and deals with a request. There is one caveat however, that if you're running CLI commands (command line) the file is not included. To set this run, open your php.ini file and look for something like the following...
Sandbox / Code Snippets /

Remove query string from URL and 301 redirect

Changing URL's to remove your Query strings can hinder your SEO score. I recently tried to pass a page title from one set of dynamically created links to the list page via a "title" param within the query string. The why's and wherefores are irrelevant right now, but the title of the page couldn't be created from the data being passed within the URL as it included town names and locations, which cannot simply be unslugified for displaying. The problem was that Google indexed all the pages with the title param and when we thought of a better solution and removed the query string, the page rank fell through the floor as we had removed thousands of pages. To create mitigate this problem, we created a 301 redirect from one page with the query string to the same page without it appended...
Sandbox / Code Snippets /

Silex and Twig debug mode

Getting debug functionality to output used to be pretty hard to do, or if not hard, then just convoluted. Whilst trying to get this working I found a few Stack Overflow entries that mentioned registering Twig extensions and setting Twig options when the object is initialised, but those are all out of date. This is how you get Twig debug mode within a Silex application...