Posts

Showing posts with the label php

3 PHP quizzes for testing your knowledge: beginner, medium, and advanced levels

Hello everyone, I have created three short quizzes for testing your PHP knowledge. They were meant to be used before job interviews as a way to provide a quick evaluation of the skill level of the applicant. They have served their purpose so I am releasing them to the public. If you really want to know your level, don't google up the answers while playing. Beginner : http://goo.gl/H9seNQ Medium : http://goo.gl/HBNezZ Advanced : http://goo.gl/5ESofc What was your score? Also, did you notice any errors in the questions? I know some of the answers can be up to debate (the regexp one in particular) but obviously if you know the answer you will pick the one that best matches what you think is the truth.  Also, keep in mind that while I consider these to be "beginner", "medium", and "advanced" levels, depending on your own skills you could laugh and consider me a newbie. It's just that from my perspective, if an intervi...

Sublime Text vs phpDesigner vs PhpStorm

Image
Lately I have been trying out several IDE solutions in order to improve my development productivity. Working on large projects made me realize that I was probably not using the right tools. Over the past year I have tried three in particular and I've got a clear winner here. So clear in fact that I thought I should write about it. The three solutions that I am comparing are: Sublime Text (multi-platform, loaded with plugins), $70 phpDesigner (Windows only), 29€ PhpStorm (multi-platform), $99 They all have trial periods so you are free to try them out for a limited time. Also please bear in mind that I am only working on PHP projects, so if that is not the case for you, you might find this article irrelevant. Sublime Text I was originally using Notepad++ as code editor, but when I started working on larger projects I quickly felt the need for something more. I was recommended Sublime Text by a friend. Let me list the pros and cons of the solution before discussi...

Access a DBISAM database with PHP via ODBC

Image
Recently I've been needing to access a DBISAM database created by third-party application, in order to export some of its data. Initially, I didn't even know what format the database was; I'd just found a bunch of files with the following extensions: .dat , .idx , .blb , .ibk , .bbk , and more. After a quick Google search, I stumbled upon a few pages that led me to DBISAM from Elevate Software . It's a proprietary database format that doesn't require a server application, somewhat similar to SQLite. Accessing the database from PHP was quite complex because I didn't have a proper reference or blog article to detail the process. That's exactly why I'm writing this: to give people directions on a subject that's hardly documented at all. In this tutorial, you'll learn how to access the database via PHP, execute a simple SQL query, and display the result. ODBC driver and connection I almost forgot: there's a catch-- even two, and here...

PHPDocFill: write beautiful PHP documentation easily

Image
Have you ever needed to write PHP code so fast that you didn't have time to properly comment it? These situations tend to happen a lot when you are being pressured by your boss (I know what I'm talking about) to deliver projects under strict deadlines.  Once the project is delivered, it is always a pain if you ever have to come back to the code and comment it.  To make it easier and more enjoyable to comment your PHP code (afterwards I suppose), I've developed a simple tool called PHPDocFill that does the following: - scans the current folder and subfolder to find all php files in your project - analyzes your PHP files to find PHPDoc documentable elements - easily insert or edit documentation blocks - it even generates a simple HTML manual based on the documentation found in all the files Full documentation, information, downloads and screenshots are available on its official site. Official site:  http://cnedelcu.net/phpdocfill/

LimeSurvey Nginx rewrite rules

I just downloaded LimeSurvey, an amazing free open-source project for creating your own online surveys , and was about to install it on my own Nginx-powered server. To my surprise, there are no available Nginx rewrite rules for it on the official project website, and I didn't even find any blog post detailing such rules. So here I go again, filling the voids. This post details: - the Nginx rewrite rules translated directly from the provided .htaccess file, the small server configuration file containing the rewrite rules for Apache. - what to do after installing LimeSurvey Nginx rewrite rules The original rewrite rules for LimeSurvey are contained in this simple .htaccess file: <IfModule mod_rewrite.c>   RewriteEngine on     # if a directory or a file exists, use it directly     RewriteCond %{REQUEST_FILENAME} !-f     RewriteCond %{REQUEST_FILENAME} !-d     # otherwise forward it to index.php     RewriteRule . inde...

JWPlayer: remembering position in video, to resume playback later

As part of my recent developments on my upload site Filetrip.net, which comes with interesting video playback capabilities, I've added the possibility for visitors who watch a video once and interrupt playback to return to the video later on and resume where they left off. In short: you are watching a video, you suddenly or accidentally close the tab or visit another site. When you go back to the video page and start playing again, the video will resume where you left off. I was wrong to assume that this was an upcoming feature for JwPlayer, seeing as one of the authors stated that they " don't support this explicitely ". So I designed it myself with minimal coding. Note that this has been tested on JWPlayer 5 and above, but I cannot guarantee that it will always work in the future. Here is how I am going to detail this tweak: 1. Introduction and requirements 2. Remembering the position 3. Setting the starting offset 4. Cookie data limitations Intro...

AVCLevels PHP Library: read and set profile level from H264 AVC-encoded video (MP4, MKV, ...)

I was stunned this morning to find out about AVC levels  (H264/MPEG-4 AVC). Basically, when you encode a video using the widespread H264 codec for the video stream, the encoder sets a flag called the "level". Wikipedia says that the level  is a specified set of constraints indicating a degree of required decoder performance for a profile . The problem I have with this is: some software and equipment restrict their own capabilities based on that level! They check the level, and if the value doesn't please them, they refuse to even attempt to play the video. What is this all about? See, I had two MP4 videos. One would play fine on my iPhone, the other refused to play (iTunes refused to copy it into my library, claiming that my iPhone did not support the video format). I inspected both files with MediaInfo , they were both encoded properly with AVC (H264) and AAC audio, similar bitrates, same resolution. After hours of testing and research I stumbled upon this blog po...

Nginx & PHP via FastCGI important security issue

A critical security issue has recently been pointed out on servers that run Nginx and PHP via FastCGI. The issue allows anyone to execute their own PHP code on the system, I don't think I have to remind you of the consequences this could have. I will attempt to provide a simple explanation of the issue and more importantly how to fix it. What is the issue? I would like to begin by discussing the nature of the problem: it is not caused by Nginx itself - it is not a bug or a security breach in itself. Actually, it is the way that people usually configure Nginx FastCGI options to work with PHP, and how PHP reacts to that configuration. Pretty much everyone adopts the same configuration without being aware of the issue. The issue itself can be understood simply, then I will explain why PHP behaves that way. Most dynamic websites allow for a reason or another uploading of files. Say, I'm running a forum-based community, users can upload images to use as personal photo or ava...

Setting up and using memcached & memcache on Linux CentOS 5/Plesk 9

Image
The second part of my tutorial on optimizing your server for hosting high traffic websites: installing and configuring memcached and the memcache php extension for your server. This is a little easier than the first step (setting up nginx as reverse proxy, see article below) and can be applied to any kind of dynamic website. What's the point ? On highly dynamic websites such as forums, news sites or any user content based website, the database server load is often very high. The more traffic you get, the more cluttered your database server becomes, sometimes rendering your website completely unavailable to visitors. Using a data caching daemon will allow you to save some data in memory instead of fetching the data from the database every time. You should know that memcached is used by major websites such as Wikipedia, SourceForge, SlashDot... need I say more? What is memcached ? Memcached is the daemon running on your server. Its usage is extremely simple, there are no confi...

The final solution: nginx+apache2 and memcached

Been a while! But I'll make up for the huge time gap: this post will probably be one of the most useful I'll ever post. I happen to be running a high traffic website, have been running it for about 5 years now. Over the past few years though, my website has known a major traffic increase which resulted in my servers being regularly cluttered and my website inaccessible. My website profile: an Invision Powerd Board based website (heavily modded though), running under PHP 5 and MySQL 5. Servers are hosted in France at OVH.com. At first, my reasoning was quite simple: spend more money on a more powerful server. I ran about 5 or 6 server upgrades over the years. I must say it worked at first, since I was running low-end servers. But for the last couple of months the traffic became way too high, which resulted in my website being completely inaccessible for a part of the world (for visitors in remote countries such as Canada, connections frequently timed out) and just plain slow for...