background preloader

PHP

Facebook Twitter

Minimal Guide to Debugging PHP with XDebug and Vim. For those of us moving to PHP from modern IDEs like Visual Studio, var_dump and die are simply not enough! Luckily, I can report a generally positive experience using Vim and XDebug as an effective debugger. Here's a short guide to installation and usage. Installation Server-side Install XDebug via your system's package manager, PECL/PEAR, or by compiling it from source. Configure your PHP installation so that it knows where to find XDebug's .so and that debugging should be enabled. . ; point this to wherever your xdebug.so is located zend_extension=/usr/lib/php5/20090626/xdebug.so xdebug.remote_enable=1 xdebug.remote_host=localhost xdebug.remote_port=9000 Warning: for XDebug to work properly, you may have to disable your Zend debugger if you have one installed (may be found in /etc/php5/conf.d/zend.ini).

Client-side Install the DBGp remote debugger interface for Vim. This script requires that your Vim be compiled with Python and signs support. Usage Optimization. Get Started with Twilio SMS: Receiving Incoming SMS Quickstart. The Twilio Quickstart Tutorials are a great place to get started and learn the basics of our cloud communication platform, but I have always found it helpful to not only be able to read about the tools I’m using but also see them in use. This led me to kick off the Twilio Quickstart Screencast series where we will go through the steps of each tutorial to both show you exactly how to get up and running with Twilio.

The series will initially be using the PHP version of each tutorial, over time we will work on expanding them to other languages as well for full polyglot goodness. I encourage you to follow along with the screencast and tutorial Receiving Incoming Text Messages to build your own awesome Twilio app: S blog: Handling Plugins In PHP. These patterns are designed to handle communication between disjoint objects. Now, one key point to note here, is that every listener would need to bind to the object instance that it wants to track. Another key point is that the Subject does not pass along any information about the cause of the update. This makes the Observer Pattern extremely useful for situations where you want to bind the state of one part of the application to the state of another. A key example of this is in a stateful MVC pattern, you can bind a view instance to observe a model instance. That way, when a controller makes changes to that model instance, it will notify all the views that are listening that it changed and they need to re-render themselves.

However, it should also be noted that the Observer Pattern creates a moderate coupling between the two classes involved (the subject and the observer) as they need to directly call methods on each other. Mediator Pattern A quick example: Functional Handlers An example: Beautiful HTML5 File Uploads using CakePHP and jQuery File Upload | Creative Ideal. Setting Up an Ubuntu Web Server | Chris Kankiewicz. Setting Up an Ubuntu Web Server By Chris Kankiewicz|Linux, Web Dev|1 Comment Having set up several Debian and Ubuntu web servers in the past I thought it would be a good idea to share my process. The following is a relatively comprehensive guide to installing and configuring an Apache based web server with some optimizations and basic resource monitoring. I primarily work with Ubuntu servers, but most of the commands here should work exactly the same in Debian or Ubuntu.

Download and Install the OS If you are setting up your own server, the first thing you will need to do is download the ISO that corresponds to your hardware (32/64-bit), burn it to CD and install it to your server. Note: It is strongly recommended that you choose the LTS (Long Term Service) release if you decide to go with Ubuntu. The installation process is relatively straight forward, so I will not be going over that here, simply boot to the disc and follow the on-screen instructions. Create a User Account Install sudo: Welcome to Imagine’s documentation! — Imagine, image manipulations reloaded. Imagine is a OOP library for image manipulation built in PHP 5.3 using the latest best practices and thoughtful design that should allow for decoupled and unit-testable code.

Contribute: Your contributions are more than welcome ! Start by forking Imagine repository, write your feature, fix bugs, and send a pull request. If you modify Imagine API, please update the API documentation by running at the root of Imagine project: curl -s | php php composer.phar install --dev bin/sami.php update docs/sami_configuration.php -v and commit the updated files in the docs/API/ folder. If you’re a beginner, you will find some guidelines about code contributions at Symfony A couple of words in defense After reading the documentation and working with the library for a little while, you might be wondering “Why didn’t he keep width and height as simple integer parameters in every method that needed those?”

It’s OOP man, come on - nothing to add here, really. Watermark Your Image With Simple Php Script - Discuss Anything. This script was found on the net B&T's Tips & Scripts site. Just in case the site may not show, I will include the code here: List of things needed:1. your image in any format2. watermark image--in gif format with transparent background3. script below with name (i.e. watermark.php) <? Php // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script // where this script is named watermark.php // call this script with an image tag // <img src="watermark.php? Name this script, i.e. watermark.php and call this script as following: the only thing you need to chage is "image_name.filetype" and of course you can have the relative path such as: The caution here is the script watermark.php and watermark.gif should be in the same location. watermark.gif should have transparent background.

CakePHP

Commit 2bffd4c26dabbe3d77ac1a92e656b249785c1024 to cakephp/cakephp - GitHub. 2.4 User Guide. PHP 5: MySQLi Prepared Statements. IntroductionThis tutorial will guide you through creating MySQLi prepared statements. MySQLi is an extension/API for PHP that is also know as MySQL Improved. MySQLi is included with versions 5 of PHP and later that allows PHP developers to take advantage of all the features in MySQL 4.1.3.

According to the manual: Quote If you are using MySQL versions 4.1.3 or later it is strongly recommended that you use the mysqli extension instead. Any more introduction to MySQLi is beyond the scope of this tutorial. You can read more at PHP: Introduction - Manual Prepared StatementsPerpared statements are queries written before any actual data is passed to the query. MySQL Official definition: Prepared statements are the ability to set up a statement once, and then execute it many times with different parameters You may be wondering why you would use prepared statements as opposed to passing the SQL statement directoy to MySQL.

Bound Parameters INSERT INTO CodeCall (FirstName, LastName) VALUES (? <? Continuous Integration for PHP – phpUnderControl & CruiseControl – HackIX: Small Hacks for a Large World. Jan 10 3 Did you know that you can auto­mate unit tests (which is the PHP worlds equalient of com­pi­la­tion checks Set up your devel­op­ment team using local check­outs of the project and have them do local PHPUnit tests, check their changes in and then get Con­tin­u­ous Inte­gra­tion checks done on a cen­tral server using phpUn­der­Con­trol that emails the team with success/fail reports, it’s a good way to work. phpUn­der­Con­trol is an addon appli­ca­tion for the con­tin­u­ous inte­gra­tion tool CruiseC­on­trol , which inte­grates some of the best PHP devel­op­ment tools. This project aims to make your first steps with CruiseC­on­trol and PHP as easy as pos­si­ble. Inte­grated tools Test­ing and soft­ware met­rics — PHPUnit is the most pop­u­lar xUnit imple­men­ta­tion for PHP that pro­vides a frame­work for auto­mated soft­ware tests.

Go and check it out today Tags: Code Coverage , CodeSniffer , PEAR , PHP , PHPDocumentor , phpUnderControl , phpUnit. 50 Extremely Useful PHP Tools - Smashing Coding. Advertisement By Jacob Gube PHP is one of the most widely used open-source server-side scripting languages that exist today. With over 20 million indexed domains using PHP, including major websites like Facebook, Digg and WordPress, there are good reasons why many Web developers prefer it to other server-side scripting languages, such as Python and Ruby.

PHP is faster (updated), and it is the most used scripting language in practice; it has detailed documentation, a huge community, numerous ready-to-use scripts and well-supported frameworks; and most importantly, it’s much easier to get started with PHP than with other scripting languages (Python, for example). That’s why it makes perfect sense to provide the huge community of PHP developers with an overview of useful tools and resources that can make their development process easier and more effective. This post presents 50 useful PHP tools that can significantly improve your programming workflow. Debugging Tools Documentation Tools Minify! JavaScript-style object literals in PHP. The object literal notation in JavaScript looks like: or var fido = {}; fido.name = "Fido"; fido.barks = true; From assoc arrays to objects In PHP you would call that an associative array.

$fido = array( 'name' => "Fido", 'barks' => true); And you can easily make it an object too: $fido = (object)$fido; echo gettype($fido); Or if you want to start with a blank object and add stuff to it: and then $fido->name = "Fido"; $fido->barks = true; A little explanation maybe: objects in JavaScript are hashes, maps, whatever you decide to call them. Objects in PHP need a class, but the new stdClass() lets you start quickly without the class {...} jazz. So far - so good. Methods anyone? JavaScript doesn't care about properties versus methods. Fido.say = function () { if (this.barks) { return "Woof! " Turns out, since PHP 5.3 there are closures in PHP too.

$fido->say = function() { if ($this->barks) { return "Woof"; }}; The difference is that $fido->say() won't work. Say is not a method. And a sprinkle of magic. Uploading Files To MySQL Database - PHP MySQL Tutorial. Using PHP to upload files into MySQL database sometimes needed by some web application.

For instance for storing pdf documents or images to make som kind of online briefcase (like Yahoo briefcase). For the first step, let's make the table for the upload files. The table will consist of. id : Unique id for each filename : File nametype : File content typesize : File sizecontent : The file itself When you click the download link, the $_GET['id'] will be set. Example : if(isset($_GET['id'])) { // if id is set then get the file with the id from database include 'library/config.php'; include 'library/opendb.php'; $id = $_GET['id'];$query = "SELECT name, type, size, content " .

$result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name");echo $content; include 'library/closedb.php'; exit; } RedBeanPHP Manual.