php

Which PHP Framework will get me to a usable UI the fastest?

There are a lot of php mvc frameworks out there now. Which one will get me to a frontend, a backend, a user system with permissions the fastest. I like the look of things like Symfony or Codeigniter but there seems to be a lot of re-inventing the wheel involved. Every web application is going to have some users, even if they're just a...

Simplest way to profile a PHP script

What's the easiest way to profile a PHP script? I'd love tacking something on that shows me a dump of all function calls and how long they took but I'm also OK with putting something around specific functions. I tried experimenting with the microtime function: $then = microtime(); myFunc(); $now = microtime(); echo sprintf("Elapsed: ...

PHP sleep() silently hogs CPU

I'm running Apache on Linux within VMWare. One of the PHP pages I'm requesting does a sleep(), and I find that if I attempt to request a second page whilst the first page is sleep()'ing, the second page hangs, waiting for the sleep() from the first page to finish. Has anyone else seen this behaviour? I know that PHP isn't multi-threaded...

When do you know it's time to rewrite an application

This is humbling, but probably something most can relate to. I am currently adding functionality to a PHP application I wrote for a client 2 years ago. In the interest of full disclosure, this was the first "real" application I ever built from the ground up, in the sense that I actually met with clients to determine and write a spec. ...

How do i resize and convert an uploaded image to a PNG using GD

I want to allow users to upload avatar-type images in a variety of formats (GIF,JPEG,PNG at least), but to save them all as PNG database BLOBs. If the images are oversize, pixelwise, i want to resize them before DB-insertion. What is the best way to use GD to do the resizing and PNG conversion? Edit: Sadly, only GD is available on the ...

What's a good way to encapsulate data access with PHP/MySQL?

Most of my experience is on the MSFT stack, but I am now working on a side project, helping someone with a personal site with cheap hosting that is built on the LAMP stack. My options for installing extras are limited, so I'm wondering about how to write my data access code without embedding raw queries in the .php files. I like to kee...

Does PHP have built-in data structures?

I'm looking at the PHP Manual, and I'm not seeing a section on data structures that most languages have, such as lists and sets. Am I just blind or does PHP not have anything like this built in? ...

PHP includes vs OOP

I would like to have a reference for the pros and cons of using include files vs objects(classes) when developing PHP applications. I know I would benefit from having one place to go for this answer...I have a few opinions of my own but I look forward to hearing others. A Simple Example: Certain pages on my site are only accessible to ...

Passing a commented, multi-line (freespace) regex to preg_match

I have a regex that is going to end up being a bit long and it'd make it much easier to read to have it across multiple lines. I tried this but it just barfs. preg_match(' ^J[0-9]{7}:\s+ (.*?) #Extract the Transaction Start Date msg \s+J[0-9]{7}:\s+Project\sname:\s+ ...

The difference between loops

It's about PHP but I've no doubt many of the same comments will apply to other languages. Simply put, what are the differences in the different types of loop for PHP? Is one faster/better than the others or should I simply put in the most readable loop? for ($i = 0; $i < 10; $i++) { # code... } foreach ($array as $index => $value) {...

Suggestions on Ajax development environment for PHP

I am a C/C++ programmer professionally, but I've created a couple of personal web sites using PHP and MySQL. They're pretty basic, and I'd like to jazz them up using Ajax, but I've never done any Ajax. I've done all the development so far manually, i.e. no IDE or anything like that. Does anyone have suggestions on Ajax development envir...

What is the best way to setup memcached on CentOS to work with Apache and PHP

What is the simplest way to install memcached on CentOS for someone new to the world of Linux? What is the best way to enable it for Apache and PHP ...

How to handle including needed classes in PHP

I'm wondering what the best practice is for handling the problem with having to "include" so many files in my PHP scripts in order to ensure that all the classes I need to use are accessible to my script. Currently, I'm just using includeonce to include the classes I access directly. Each of those would includeonce the classes that the...

Classes vs 2D arrays

Which is better to use in PHP, a 2D array or a class? I've included an example of what I mean by this. // Using a class class someClass { public $name; public $height; public $weight; function __construct($name, $height, $weight) { $this -> name = $name; $this -> height = $height; $this -> weight = $weight; } } $classArra...

Am I In A Death March Project?

The facts: The other programmer is constantly slipping deadlines with no status updates, at the moment he is slipping the single biggest feature on the website (which he asked to work on) by 3-4 weeks from his initial estimate. The people for whom the software is being written fear taking action against the other programmer because the...

Embedding IPTC image data with PHP GD

I'm trying to embed a IPTC data onto a JPEG image using iptcembed() but am having a bit of trouble. I have verified it is in the end product: // Embed the IPTC data $content = iptcembed($data, $path); // Verify IPTC data is in the end image $iptc = iptcparse($content); var_dump($iptc); Which returns the tags entered. However when I...

Setting PHP Include Path on a per site basis?

I can set the php include path in the php.ini: include_path = /path/to/site/includes/ But then other websites are effected so that is no good. I can set the php include in the start of every file: $path = '/path/to/site/includes/'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); But that seems like bad practice and ...

Tactics for using PHP in a high-load site

Before you answer this I have never developed anything popular enough to attain high server loads. Treat me as (sigh) an alien that has just landed on the planet, albeit one that knows PHP and a few optimisation techniques. I'm developing a tool in PHP that could attain quite a lot of users, if it works out right. However while I'm fu...

Where can i find extended HTML reporters for Simpletest?

I am using Simpletest as my unit test framework for the PHP site I am currently working on. I like the fact that it is shipped with a simple HTML reporter, but I would like a bit more advanced reporter. I have read at the reporter api documentation, but it would be nice to be able to use an existing reporter, instead of having to do it ...

Images in PHP

Is it possible to create images with PHP (as opposed to simply linking to them via HTML) and if so, where should I go first to learn about such a thing? ...