Tag Archives: PHP

Userland Multitasking: Introduction

Difficulty

At my current level of skill and understanding, this feature would be impossible for me to implement on my own. It is just an introductory look at what the other sections will visually look like when they are also finished. I will not be implementing this feature.

Introduction

Multi-threading should not be allowed at the user level, but allow for sandbox threading. The PHP Engine should keep track of the creation of threads, protect against deadlocking, and control synchronization. This will abstract away the complexity and have PHP do all of the heavy lifting as well as protect the developers from themselves and harming the process the thread is in.

There are some architectures, both CPU and OS, that do not allow threading. There should be a fall back implemented in the virtual machine that still enables an environment functionally similar to threading. The fall back can be implemented like the ticks in the current PHP Engine or it could use a stack approach similar to operating systems.

The Engine could also track how efficient the system is and how well it would perform if it was single threaded. There should be a mix of allowing the developers to test and optimize on their own and tracking internally to help protect against slow scripts caused by wrong usage of this feature.

There should be internal reflection for threading to allow for tracking, overriding, and debugging. The reflection will track the time a thread takes, which threads and variables it is synchronized with, and how many times faults occurred. There should be functions for overriding whether or not the thread is still multi-threaded or if it creates an interprocess, or if it is instead acts like a single thread, when processed.

The multi-threading feature wouldn’t be useful, if the process shutdown and destroyed everything at execution. The feature would only be enabled for PHP environments that are already multi-tasked to keep the script from taking longer than it should.

Virtual Machine: Timing the Best Method

During runtime, the virtual machine can keep track of the time the script takes and switch between single threaded and multiple threads to get statistics on which would be the best method overall. After it figures which is the best method for the user, it can either log what it finds, allow for reflection to get the number, and then decide which is the best method to take. It would still work like the user expects, but allow for the virtual machine to decide which is the best method for the user.

This would add additional memory and processing overhead, so it could be disabled by those who already think that their script is optimized enough already. This adds another level of complexity to the feature and could introduce difficult to find and fix bugs. It should also be allowed to be overwritten by the user for those who know for a fact that the system doesn’t work that well for their script. The system won’t be able to work perfectly 100% of the time for every script.

This additional feature would be extremely useful for JIT or opcode cached environments where the script is stored in memory for extended periods of time. Keeping track of timing of various environments would allow for the system to rewrite itself to optimize the speed for the user. The abstraction would be such that the user wouldn’t be able to tell, except when the system fully realizes and optimizes itself and the script.

Keywords

The following sections will introduce additional keywords and syntax that will require that the flex and bison skeletons be updated to allow for this feature. This section will not be updated and will not be found here.

Different Methods for Creating Threads

The following parts will detail the various parts of this feature and will be split up to allow for better understanding on what the feature will involve.

  1. Anonymous

    • Does not allow for returning to main thread or calling from the main thread.
    • Runs along side the main thread.
  2. Named

    • Does not run unless called from the main process.
    • Can return data to the calling thread.
  3. Shell

    • Allows for shell commands to be processed in another thread or process.
    • Allows for returning to the calling thread.
    • Allows for both anonymous and named shells.
    • It would replace functionality, most of the shell extensions, when implemented.
  4. Interprocess

    • Replaces the current method of the Process Control extension with an easier to setup and create method.
    • Also will allow for connecting to other processes for passing data.

Possibly Related Posts:


PHP Opcode Series

Introduction

The PHP Opcode series will take a look at the theory and implementation of working with the Zend Engine in the specific areas of adding opcodes and enabling language features. The specific areas will be how it would look in the PHP language, how it would look as PHP opcodes, and how it would look as Assembler for looking at enabling JIT compiling later.

The posts will be researched and go through multiple drafts for professionalism before posting. In this hope, it will strive to enable discussion that isn’t flaming and collective of the topic at hand. For as much as I can achieve at my level of writing skill and researching the topic at hand.

(Honestly, I’m spending more time on these posts than I do on my school research papers… which is to still say that I am doing more than previous posts.)

Purpose

I want to add JIT compiling to the current Zend Engine and before I can do that I will have to learn how the Zend Engine works. The best way would be to read a book or learn from the minds that created it. There is a current lack of printed material on extending the Zend Engine and I’ll rather not bother the Zend Engine masters with my countless n00bish questions. I’ll wait to ask those questions for whenever I hit a road block or can’t find the answer myself.

I’m going to try to implement some of the easier features of the “Opcode Theory” part to learn how different areas of the Zend Engine work. I’ll also intentionally break the Engine and learn from there. Such questions as, “I wonder what would happen if I add this?” or “What if I change this to my own code.”

I’m tempted to rewrite the entire thing to my achieve my own goals, but that would negate the point of these exercises.

Not that I will implement all of the theory, but to think about how it would be possible. To learn how PHP uses Opcodes and how it can be improved and optimized by using more. By writing theory and how the current Zend Engine works, I can remember better and try to implement my ideas to see if they are possible.

Areas of Focus

There will be areas of focus with titles for keeping order of which post is for what.

  • Opcode Theory
  • Opcode Implementation
  • Opcode Documentation

Opcode Theory

These posts will abstract out the problem and how it could look once implemented. From above, the sections will be PHP userland code, PHP Opcode, and finally how it would look as Assembler for JIT. The Assembler isn’t much use for the JIT, but it will help to think about solutions once JIT is finally implemented. The JIT and Assembler will achieve the same functionality of converting opcodes to machine code.

It would be nice to see it in action outside of PHP, using Assembler, before implementing the feature using the JIT library. Getting Assembler code to work against the Zend Engine and PHP will also be part of the Implementation, which is outside the scope of the Theory. It is just to say that the Theory part will have puesdo-Assembler code for how it might look.

I will not be implementing all of these theory posts and I will be lucky if I even implement one. My main purpose is learning enough of the Opcode parts of the Zend Engine to hook into and write a Zend Engine extension that enables JIT compilation. These side projects should help to learn enough to accomplish that much.

Opcode Implementation

Will document how well I’m doing implementing some of the theory and eventually the JIT feature for the Zend Engine. In the event that I do implement one of the features in the theory part, I will post what it finally looks like and how it works. These posts will also include the road and difficulties in implementing the features in the theory posts and eventually how it was done.

Opcode Documentation

I expect that I’ll learn a lot by the above mangling of the Zend Engine and picking at the minds and team behind the Zend Engine. Some things I will have to learn myself and I’ll post them in this heading to make sure that I’ll remember them when I come back after an extended break or two to work on other projects.

“Hmm, how did I do that one thing again? Oh yeah, I wrote about that!” and also to store help I will eventually (hopefully) receive from the PHP lists.

Possibly Related Posts:


Writing Manuals for Users

We all know that we must write documentation in code, else we be hit on the head with a blunt object. This goes deeper than that, to the dreaded details for those who do not wish or cannot read code. It also goes to what makes a better library than another. Doesn’t mean that the documentation has to be perfect, just that it exists.

Damn phpDoc, Damn phpDoc to Hell!

Just Kidding, phpDoc is very useful and should be used in development. There are some difficulties with information the phpDoc documentation web sites provide. In most cases when @example tag is not utilized effectively or not at all.

It really is the primary concern that I have when reading through phpDoc sites that no true examples are given to places the method or function or class usage in context. Yeah, you tell me what it does, but how exactly do I use it? I would like to use two different sites for an example, the php.net manual and the SPL phpDoc site.

The PHP manual is great because not only does it state what the function is and the parameters, but also gives examples. The SPL phpDoc gives you all you will ever need to know about the SPL classes and interfaces, but there is a very good reason why there are so many tutorials out there for SPL. The popularity of external tutorials for SPL is that there exists no examples on the SPL phpDoc site.

An advanced developer could take a look at the site documentation and do a few tests and have a working implementation. What about the rest of us? The lowly mortals that do not have such time to experiment and devote time to figuring out how to use the various classes.

It would explain why I instead choose to write my own ArrayObject every time I need the functionality. I know how to use Countable, Iterator, and ArrayAccess, so why is ArrayObject any more difficult? I should not have to depend on the talent (and kindness) of other developers and would be better served by the “official” site for such information.

(I think of SPL as an exception to this article’s rule because it comes with PHP and offers advantages not otherwise available.)

Making Better Libraries

You can have the best API out there, whether object or procedural, but without some guide to use it, no one will. I’ve sought out many libraries that I threw out, because the author didn’t take the time to write a manual on how to use it. Now, you might say I’m whining and you’ll be correct. I have little time to go through hundreds or thousands of lines of code just to solve what should be an easy operation.

To give an current example on how manuals should be, notably the Zend Framework, in the beginning the documentation wasn’t perfect (complete would be a better description and still isn’t at this point). Still, it is fine because most of the questions can be answered by reading what exists. I can provide feedback on how it can be further improved, because there is a manual.

It is worse to have no written manual than poorly written (clarity, grammar, spelling, missing sections) documentation. Proving that you at least tried means more than the appearance that you either don’t care or don’t have the time.

If you are writing a public library, it at least says that you want people to use it at some point. It might be the most boring and torturous experience known to a coder, but it is well worth the effort (unless your library is terrible, but at least you can take the experience and use it in a job setting).

Improving the Manual

One of the biggest fears of writing a documentation is that it must be perfect. Not true, states this author, for I can never write a perfect manual. I’ll be damned if I’m not going to try, knowing that I’ll fail. At least there would be something to show and to receive feedback saying, “Your documentation sucks!” At least I’ll be able to reply, “Oh yeah! Where exactly can I improve it?”

Just start writing it and if you have clarity or other problems, a helpful user might let you know. A even more helpful user is going to let you know the exact phase to make it perfect or help provide the improved documentation on their own.

Help your users by providing a more detailed context of how to use the library and slowly try to improve it as time permits. If no one offers to help, then carry on improving the manual on your own. It would only help you understand your library better and help your existing users on using your library.

It is easier to tightened a few spots here and there than to write whole sections or the whole manual. If you at least have something that exists it is going to be quicker to update it to improve the existing sections or adding new sections. Think of it as an investment and own it.

Conclusion

Really, however you go about doing it, comments in code is to help yourself and anyone that dares to try to maintain it in the future. Knowledge without context is worthless to your user, so my advice is to either utilize the @example phpDoc tag or write a manual along with the phpDoc site to relate the usage better.

At the very least, you’ll be able to better answer questions by saying, “RTFM.” Or at least a more polite phase or link to the section they are asking about.

Possibly Related Posts:


Dijkstra Path Finding Algorithm

Update March 21, 2007: Will be updated to work starting with Revision 278
Update March 31, 2007: Will be updated to work starting with Revision 285

Warning: Dijkstra is greedy; usage with large coordinate boundaries may timeout.

Even with the Singleton Dijkstra class, I still would have created my own. The reason is that I needed to create a work flow for the A* algorithm. The A* (A-star) algorithm is better as it is more efficient and only searches the nodes going towards the end node. A* is also a little bit more difficult compared to the Dijkstra algorithm. At least with the work flow, either algorithm could be used with little addition work. All the finished A* algorithm would need is to load the heuristic object along with the measure object.

Truthfully, my coding is incorrect in that it doesn’t follow the weighted edge, but instead assigns a fitness to all nodes. From my research it seemed that the edges would be assigned the distance from the start node and then the path would be traversed after.

My algorithm instead assigns the fitness from the actual distance of the node from the end node. It does not stop when the end node is reached because it needs to make sure that no other nodes could be used to reach the end, in case of a blocked path somewhere.

My Dijkstra algorithm might need refactoring later, but it works currently and that is all I care about. It seems that fudging is okay in game development, so I’m going to assume that since it harms none that it will be okay.

Read more for the tutorial on how to use the classes.
Read more »

Possibly Related Posts:


AI in PHP Games

With the next generation of PHP games using Ajax, the developer can afford to allow better user interaction with battling and Non-Player Characters. Some work can make a game seem more life-like and harder for the player to figure out.

For AI usage, testing and CPU, memory, and storage issue might sway developers away from the more advanced techniques. Not every problem needs a neural tree or genetic encoding for the solution and would be better served with a little bit of creative engineering with traditional means.

Traditional methods have the disadvantage of handling only a known set and can’t be trained for unknown habits that users might exploit. Calculations have the disadvantage of reverse-engineering and possible float bugs. So it would be useful to research AI methods to handle some problems.

The following is a list of problems and possible solutions for current and future PHP games. It is my goal with a few projects to see just how much can be accomplished in the field of online browser PHP games. Another focus is to see how much of a cost is added by using AI.

Problem 1: Calculating Distances in Real Time

Description

There are games that have you wait on moving objects across distances. The traditional approach has been to just use a set calculations which is easily figured by the player. The paths through enemy territory, which would otherwise be avoided (unless initiating a battle) are passed through in all instances.

Solution

There are path finding algorithms, such as Dijkstra, A*, and so on that could be used to accurately find the distance around enemy territory and other blocked locations, say a black hole.

Little can be given on the speed of large proportions, however small sizes are quite fast (logically of course). I plan on doing tests are larger sizes, such as 10k fields and 100k fields, when the classes are passed the testing stage.

There is a completed example for which to work with. My implementation is a lot different and not completely finish.

Problem 2: Enemy Behavior – Shifting Strategy

Description

The problem I’ve came across in RPG games is that the monster just pounds you with randomized attacks. It would make more sense for the monster if it changed its attack pattern for when you are low on health during the start of the battle or grow weaker. It should also try to prepare for spells and try to block attacks whenever it is low on health or run away.

Solution

Giving the enemy life wouldn’t all that difficult to do with traditional methods, but it would require a whole lot of conditional statements. A better method if it could be afforded, is to use Fuzzy Logic or at the very least finite state machines. Fuzzy Logic does require a lot of math and knowledge of set theory (or books and other resources that offer that information instead :-) ).

Problem 3: Enemy Behavior – Learning

Description

How fun would it be that along with the enemy shifting it’s behavior it evolved in it’s technique? If the player is more inclined to use physical attacks, the enemy would start using physical blocking and spells for which to minimize the effects of physical attacks.

Solution

This can also be done using the traditional methods, but it would also be a very long list of conditional statements. A CPU extensive approach, but neater would be to use either genetics or neural networks for the learning. You could also spend time teaching the enemies yourself before the game goes live. Having the game available to what could be a massive amount of people would allow the enemy to well adapt to the players differing strategies.

Problem 4: NPC Interaction – Dialogue

Description

While not important in all games (should be anyway), it would be nice in RPGs, if you received your some of your missions from talking with NPCs. Say a NPC is missing a child and needs for you to search for the missing person. Most of the time, that discussion is fixed and scripted far before hand, and in most computer games as well. The difference is that in PHP games, there is no disconnection between the possible missions and which NPC gives the mission. It is that NPC gives that mission and nothing else.

Something else would be for NPCs that don’t have any missions to give. What about them? I would rather have them be a little bit more intelligent than old 2D RPGs, and have an open discussion depending on how far along you are and if you choose good or evil side. It would get pretty old to have the conversation with the NPC go on longer than 30 minutes or 10 minutes.

Solution

Very intelligent developers and scientists have already developed and worked on this for more than a decade. There is already an PHP library for which to use it in an application. So really, the only thing the developer has to do is spend time writing for which the library will use. It will require work, however not as much as the time it took to write the library in the first place. It would also add that special touch that other games wouldn’t have.

References

  • AI Game Programming Wisdom 1
  • Data Structures and Algorithm Analysis in C++. Pgs 339-346.

Possibly Related Posts:


Adding Look Up Tables

At the cost of memory overhead, it is useful to have a look up table to save time. The solution came from having a search method that would look up to see if the element existed each time. With all of the times I would be calling the search method, it made sense to create a look up table.

The Search method before the look up table used a while loop to iterate through the elements and tried to find the correct one to return. It became apparent that I would of had to use this search method more than I would like to continuously search through the entire array each time I wanted to position. That and this search method only returned the node and I would sometimes need the index (which would be easy to add, since the internal container is an array and the key would be the index).

    public function search($x, $y, $z = 0)
    {

        $this->rewind();

        while($this->valid())
        {
            $cur = $this->current();

            // Check that the x value is the same. Quicker to check the x pos
            // first and continue then to check all values at the same time.
            if(!($cur['x'] === $x))
            {
                $this->next();
                continue; // Possible Bug
            }

            if(!($cur['y'] === $y) && !($cur['z'] === $z))
            {
                $this->next();
                continue; // Possible Bug
            }

            // If all checks pass then current be returned ending the loop.
            return $cur;
        }

        return false;

    }

After all of that, I would have to create unit tests to make sure that if the x position didn’t exist, that it continued without testing for the y and z positions. Failing that, I would have to use another method to repeat. I however was able to reduce the search method to the following efficient and speedy code.

    public function search($x, $y, $z = 0)
    {
        if($this->_searchCoordIndex($x, $y, $z) === true)
        {
            $index = $this->_coordsIndex[$x][$y][$z];
            return $this->_coords[$index];
        }
    }

The look up table prototype:

class Quantum_Coordinate_Array
    implements SeekableIterator, Countable
{
    /**
     * Keep a look up table of the coordinate indexes.
     */
    protected $_coordsIndex = array();

    public function search($x, $y, $z = 0);

    protected function _setCoordIndex($index, $x, $y, $z = 0)
    {
        $this->_coordsIndex[$x][$y][$z] = $index;
    }

    protected function _existsCoordIndex($x, $y, $z = 0)
    {
        if(isset($this->_coordsIndex[$x][$y][$z]) && $this->_coordsIndex[$x][$y][$z] != null)
        {
            return true;
        }
        return false;
    }

    protected function _searchCoordIndex($x, $y, $z = 0)
    {
        if(!array_key_exists($x, $this->_coordsIndex))
        {
            return false; // X key does not exist
        }
        else // X key exists
        {
            if(!array_key_exists($y, $this->_coordsIndex[$x]))
            {
                return false; // Y key does not exist
            }
            else // Y key exists
            {
                if(!array_key_exists($z, $this->_coordsIndex[$x][$y]))
                {
                    return false; // Z key does not exist
                }

                return true; // All key exists
            }
        }
    }

}

Apparently also, the _existsCoordIndex and _searchCoordIndex do exactly the same thing, except the logic for the _existsCoordIndex is quicker. The _searchCoordIndex would have to be unit tested, but it would be more accurate than _existsCoordIndex (if it is needed and desired).

Possibly Related Posts:


Touring OmniTI

It was by chance and this crazy post that caught the attention of Laura Thomson that I was able to visit OmniTI. To me, the professional world exists at another level above average existence. I never thought I would be able to tour any business establishment, so I didn’t think to ask in a sane matter. It is impressive that any company would open their doors to the average person who is not a customer.

The Talk

I was expecting, just to be shown around, ask a few questions about how the place was run, and be kicked out the door. However, I think it was a treat to actually sit down and have a discussion with Laura, George, and Wez after the tour. It was fun to engage in a PHP discussion without having the other person just nod. Talked about PHP and some other stuff.

The Tour

Why it was exciting?

To be able to meet some prominent developers and leaders of PHP, who wouldn’t be excited?

It might not sound like much, or at least it didn’t seem like much to the people I told, but from an academic perspective, it was a chance to see what it like in a professional development office. There is some anxiety to not knowing what happens at a professional workplace and leaves much to the imagination. I really had no idea what to expect and I can imagine that if I ever do get a professional job that the place would look something like OmniTI, until I do get a professional job and find it is exactly like Dilbert.

The details

I was kind of shocked at how the developers worked in such an open space. One without cubicles and with wavy desks. It does help to lighten the mood, in my opinion. It is quite depressing to be confined to a tight space, maddening even. I had to clean cubicles, it was depressing just being in there just for a few seconds. I think it is just the idea of isolation in a room full of people. You could die and no one would know until they either smelled your corpse or walked by.

The layout was logical, keeping the “work” and the “client” areas away from each other. However, the “boss” areas are quite close to the work area, so slacking off probably isn’t an issue, since you can’t hide, like you can in a cubicle.

I probably should have said something about not being able to hear, but I mostly caught the gist of the speaker. Well, it wasn’t that I couldn’t pick up and understand the complete conversation. I did miss a few joke cues, because it took to long to realize what was being said was a joke. It is one regret that I keep forgetting that it is okay to tell people that I have a hearing problem.

Wez was cool.

Yeah, Chris had left before I arrived, but Wez was there, which was just as cool. What was also cool was that Laura invited him to join in on the tour, so I had two people showing me around. Wez did reference a few things on my blog, both good and bad.

Wez was the complete opposite of what I imagined. I kind of thought he would be wider and shorter, but no, he is a giant (at least 6 feet) and skinny. Reminded me of a friend I have, except Wez is skinnier. It is the shirts I think, which is why I tuck my shirts in. I’m fat, but eh, I don’t want to look any bigger than I am now.

I do have frustrations with PDO, but it is mostly from learning something new. I thought it was and still is a great feature to have in PHP. I’m glad I had a chance to clarify that to him personally.

“We aren’t going to let you leave here alive.”

I didn’t reply to this for two reasons. The first reason was that I knew it was a joke, which was stated later in the tour. The second was that I had thought to say, “Yeah, I would like to see that happen,” or, “Whatever you want to do,” but I thought about it and it didn’t seem like a good idea to test fate and find that they had a Plan B “just in case.” I would have been more concerned if they knocked me out and I woke up tied to a table and suddenly hear a chainsaw starting in the background.

I also didn’t want to say, “Yeah, I say that all the time too,” and freak out the host, it is never good to potentially freak out the host. I discuss killing people all the time, so it wasn’t a big deal to me. For me, if I was really going to kill, then I wouldn’t tell it to their face, unless I was about to pull the trigger.

I do have a mental list (as to not leave evidence), but it is doubtful that I’ll ever kill them. Torture, yeah maybe. I think torture is more fun anyway. You can only kill someone once, but you can torture them for as long as you think they should live. It also leaves hope that they might make it out alive, which you can crush under the weight of a bullet hitting them in the heart. Make sure you laugh, it is more crazy that way.

Possibly Related Posts:


Zend Framework: Authentication Library Proposal

I think the idea of releasing packages based off the Zend Framework is a great idea, like the Google Data Client Library. If I could propose that they add an Authentication package including OpenID, LID (not really authentication or I should say includes more than just authentication and you can use OpenID with the newer specifications), and the others. Not part of the core of Zend Framework, but available for those who wish to use it.

The Yadis specification library uses a similar component to that of the Zend Service component and therefore could be used in one part to handle the request. The Yadis specification is really easy, other than the HTML regex to gather meta data to get the location of the Yadis XML file. All you need after you have the Yadis service file is to just use either DOM or SimpleXML to parse it and return the services.

Yadis is great for letting scripts know what services are available and where the service is located. Supposedly, it is to be used along with OpenID, but isn’t required.

Started a project a long, long time ago, around Summer-ish. Yeah, dropped it because Zend Framework had a component I was working on. Sigh. Still I mean, it would be nice if it was part or a optional component for the Zend Framework. I would do it, but I mean, HTML regex scare me. Can do XML.

Possibly Related Posts:


Zend Framework: Why not ArrayAccess?

Updated:

I’m pretty much kicking myself. In all my tests, I never once thought about returning an actual array!

“Pfft, that would be too easy!”

I suck.

Lines 35, 36: Add ‘ArrayAccess’ to the end of the line 35

class Zend_Config implements Countable, Iterator, ArrayAccess
{

Add anywhere in the class that you feel makes sense. In my version 0.1.5 preview release, I placed it in lines 80-98:

public function offsetExists($key)
{
	return $this->__isset($key);
}

public function offsetGet($key)
{
	return $this->__get($key);
}

public function offsetSet($key, $value)
{
	return $this->__set($key, $value);
}

public function offsetUnset($key)
{
	return $this->__set($key, null);
}

Yeah, I mean. After looking at the code a little bit, it became somewhat clearer on how the object functioned and how it got passed my previous post restrictions. Really simple actually.

The point I should make is that offsetSet bypasses the protected magic Set method, therefore, since I can’t test it on 5.0, it would be hard to say if it would still work or not.

The issue of code duplication is resolved by using methods that already exist. For objects that return arrays, it is possible to use the same methods listed above for any class that also use the property overloading magic methods.

Use at your own risk!

Uses the Zend Framework Config class.

$DoNotTouch = new Zend_Config(Zend_Config_Xml::load('/path/to/config.xml', 'secretdata'));

// Property

$value = $DoNotTouch->key->key;

// Or Array

$secret = $DoNotTouch->asArray();    // Iterates over all values and returns as PHP Array
$value = $secret['key']['key'];

Or simply and without as much overhead:

$DoNotTouch = new Zend_Config(Zend_Config_Xml::load('/path/to/config.xml', 'secretdata'));

// Property

$value = $DoNotTouch->key->key;

// Or ArrayAccess
$value = $DoNotTouch['key']['key'];

Possibly Related Posts:


Zend Framework: Hackish Include Path Solution

Looking over the Zend Framework Tutorial and trying to get the php_value to work, seemed to have no results. This is from the my script running in a CGI environment and the php_value working in a mod_php environment. The solution for a CGI environment is a simple one, but it did take a little bit of research to find.

For the tutorial, totally awesome, but I would add a few things to it.

  1. Reference that php_value requires mod_php environment.
  2. Example for those who don’t use mod_php.

<sarcasm>
I’ve had problem with Zend Framework not being able to find its files, which is usually not good. The “workaround” of adding the realpath works, but would be overwritten when updating. Besides, going through the files just to add realpath locations is a hassle.

The php_value only works with mod_php, so good luck if you are running PHP using CGI/FastCGI. Actually, you’ll have no luck, because it won’t work using CGI.
</sarcasm>

The Ultimate Hackish Solution

Doing some research bought up that ini_set does allow you change the include path for the script.

ini_set('include_path', PATH_TO_ZEND);

Change PATH_TO_ZEND to the absolute path to the root folder where zend.php is located. (Should be the directory that contains a Zend folder also.

Update: Better examples are in the comments.

Possibly Related Posts: