php

php is_dir returns true for non-existent folder

Has anyone encountered this oddity? I'm checking for the existence of a number of directories in one of my unit tests. is_dir is reporting true (1) in spite of the folder not existing at the time it is called. Code looks like this (with a few extraneous intermediate vars to ease debugging): foreach($userfolders as $uf) { $uf = spri...

SQL Pagination

I am trying to paginate the results of an SQL query for use on a web page. The language and the database backend are PHP and SQLite. The code I'm using works something like this (page numbering starts at 0) http://example.com/table?page=0 page = request(page) per = 10 // results per page offset = page * per // take one extra record ...

Help me construct a complex SQL query (or queries).

As part of a larger web-app (using CakePHP), I'm putting together a simple blog system. The relationships are exceedingly simple: each User has a Blog, which has many Entries, which have many Comments. An element I'd like to incorporate is a list of "Popular Entries." Popular Entries have been defined as those with the most Comments in ...

Should we stop using Zend WinEnabler?

Our system uses Zend WinEnabler. Do you use it? Is it obsolete? Should we stop using it? Is it known to cause handle/memory leaks? Here is an (old) introduction to it: "PHP Creators Unveil New Product that Makes PHP Truly Viable for Windows Environments" http://personalweb.about.com/b/2004/03/29/zend-announces-winenabler-enabling-php-fo...

Best way to hide DB connection code in PHP5 for apps that only require one connection?

Below I present three options for simplifying my database access when only a single connection is involved (this is often the case for the web apps I work on). The general idea is to make the DB connection transparent, such that it connects the first time my script executes a query, and then it remains connected until the script termina...

What is wrong with this PHP regular expression?

$output = preg_replace("|(/D)(/s+)(/d+)(;)|", "//1,//3;", $output); I'm trying to replace all alphabetical character followed by one or more whitespace characters (tabs and/or spaces) followed by one or more numerical characters followed by a semicolon with the alphabetical character followed by a comma followed by the numerical digits...

Running a scheduled task in a Wordpress plug-in

I'm trying to write a Wordpress plug-in that automatically posts a blog post at a certain time of day. For example, read a bunch of RSS feeds and post a daily digest of all new entries. There are plug-ins that do something similar to what I want, but many of them rely on a cron job for the automated scheduling. I'll do that if I have ...

CakePHP ACL Database Setup: ARO / ACO structure?

I'm struggling to implement ACL in CakePHP. After reading the documentation in the cake manual as well as several other tutorials, blog posts etc, I found Aran Johnson's excellent tutorial which has helped fill in many of the gaps. His examples seem to conflict with others I've seen though in a few places - specifically in the ARO tree...

Call to a member function on a non-object

So I'm refactoring my code to implement more OOP. I set up a class to hold page attributes. class PageAtrributes { private $db_connection; private $page_title; public function __construct($db_connection) { $this->db_connection = $db_connection; $this->page_title = ''; } public function get_page_title() { return $this->...

Best PHP Framework w/ AJAX Support?

Question I'm fairly familiar with many of the PHP frameworks out there, but I'm wondering which ones actually integrate AJAX functionality and which ones do it well? Ideally I'd love to find a framework that would allow me to avoid JavaScript alltogether (at least for typical/basic JavaScript functionality). Does such a thing exist? If...

Apache Download: Make sure that page was viewed before download

The job at hand: I want to make sure that my website's users view a page before they start a download. If they have not looked at the page but try to hotlink to the files directly they should go to the webpage before the download is allowed. Any suggestions that are better than my idea to send out a cookie and - before the download sta...

How do prepared statements work?

I'm writing some DB routines and I'm using prepared statements. My environment is PDO with PHP5. I understand prepared statements primarily provide a performance benefit, as well as some auxiliary bonuses such as not having to manually SQL-escape input data. My question is about the performance part. I have two implementations of a g...

Php function argument error suppression, empty() isset() emulation

I'm pretty sure the answer to this question is no, but in case there's some PHP guru is it possible to write a function in a way where invalid arguments or non existent variables can be passed in and php will not error without the use of '@' Much like empty and isset do. You can pass in a variable you just made up and it won't error. ...

Unique key generation

I looking for a way, specifically in PHP that I will be guaranteed to always get a unique key. I have done the following: strtolower(substr(crypt(time()), 0, 7)); But I have found that once in a while I end up with a duplicate key (rarely, but often enough). I have also thought of doing: strtolower(substr(crypt(uniqid(rand(), true)...

How do I implement a HTML cache for a PHP site?

What is the best way of implementing a cache for a PHP site? Obviously, there are some things that shouldn't be cached (for example search queries), but I want to find a good solution that will make sure that I avoid the 'digg effect'. I know there is WP-Cache for WordPress, but I'm writing a custom solution that isn't built on WP. I'm ...

Kill a specific PHP script running on FastCGI / IIS?

I'm a PHP developer, but honestly my knowledge of server management is somewhat lacking. I fired off a script today that took a regrettably long time to run, and because it had an embedded call to ignore_user_abort(), pressing "stop" in the browser was obviously futile. There was a time limit of 15 minutes enforced in the FastCGI setting...

One big SQL Select statement or several small ones (Performance)?

Hi everyone, I'm building a PHP page with data sent from MySQL. Is it better to have 1 SELECT query with 4 table joins, or 4 small SELECT queries with no table join (I do select from an ID). Which is faster and what is the pro/con of each method? PS. I only need one row from each tables. ...

How do I keep a mySQL database secure?

I'm going to be implementing a PHP/mySQL setup to store credit card information. It seems like AES_ENCRYPT/AES_DECRYPT is the way to go, but I'm still confused on one point: how do I keep the encryption key secure? Hardwiring it into my PHP scripts (which will live on the same server as the db) seems like a major security hole. What's th...

PHP: How do I check if all public methods of two classes return the same values?

In effect, if I have a class c and instances of $c1 and $c2 which might have different private variable amounts but all their public methods return the same values I would like to be able to check that $c1 == $c2? Does anyone know an easy way to do this? ...

Find out where your PHP code is slowing down (Performance Issue)

Here's my first question at SO. I have a internal application for my company which I've been recently ask to maintain. The applications is built in PHP and its fairly well coded (OO, DB Abstraction, Smarty) nothing WTF-ish. The problem is the applications is very slow. How do I go about finding out what's slowing the application down...