Tag Archives: Theory

A WordPress PHP Extension

I’ve been playing around with this idea for a while and I think it would be very interesting concept to complete. The concept is simple and most of the code will be easy. The concept part is take what is most often used and least optimized and rewrite it in C/C++. The easy part is that you can sort of do similar coding structure, albeit with pointers and zvals, but the code can be structured in the same way, well mostly.

The disadvantage of taking an almost 1:1 approach from PHP to C/C++ is that the result code may only be slightly faster (between 15% to 30% increase of performance). Comparable, it might be even faster to instead use C and C++ to the full advantage and use algorithms based completely on them.

However, it would be interesting to enable the Plugin API to execute in linear time with some of the logic. The Plugin API would be a really great first testament of the PHP Extension and it would be interesting to implement other features within it. However, I think just having every function within C/C++ would be a good initial effort.

The initial release has to be released quickly, be optimized as much as possible. If you don’t optimize the C code as well, then you can have just as bad performance. It should be fun, but I hope that I’ll have the fortitude to actually finish the plugin API part to enable benchmarking between the PHP and PHP Extension.

Possibly Related Posts:


Web Application Installer/Upgrader

I’ve been contemplating this problem. I think the system should support three methods rated based on the preferred methods.

  1. SVN (version control, preferred method)
  2. PEAR
  3. HTTP

I would prefer Subversion (VC)

This should be the preferred since the version control already has a system in place for downloading, updating (upgrading), and merging based on what changes someone has done. It would only need to get the URL to the subversion and have the location of the Subversion application or by checking if the Subversion extension for PHP is installed.

This wouldn’t require that the installer move the old files to another folder and can assume that subversion can clean up any changes. There might be problems when conflicts occur, but I think for the majority of people that would used this method wouldn’t have problems if they left their files alone.

I think this will be possible without too much trouble. First search for the SVN extension and use it, else search for the SVN application.

If neither exist, then go to the next method.

PEAR

PEAR is an awesome method of installing an application. If I can create a PEAR channel and use that to install WordPress, I can also use it to upgrade WordPress, when it needs to be. This could will need further checking. It needs access to PEAR, either the command line, or PHP extension.

This would most likely require moving any changed files over to a new folder and allow the person to copy over what they changed. I don’t know how PEAR handles these situations, but it is better to be safe than sorry in this type of situation.

If neither exists, then go to the next method.

HTTP

Not the best method as it would require moving existing files in the event that some might have been changed. The other problem is that like the above, it would require that the four methods work of GETting a file work. If any of them fail, then the installer would be broken and have no other fall back.

If None of them Works

However, I do think that for most people at least one of the methods above would work for most people. Those that it doesn’t work for, would have to use the age old FTP method or try to find someone that will do it for them.

It has to just work

This means that for most people it has to just go out there and try to find the most common places where Subversion and PEAR exist, if they are installed. It should also try to use multiple methods of getting a file by URL. It should allow for configuring the locations and methods used instead. An “auto” method for novices or people who just want it to work and a “manual” method for more experienced users or for people who want more control.

If it works out, I will apply it to installing Astrum Futura.

Possibly Related Posts:


SuperBad is Super Gay

Damn good movie by the way. Funny as hell.

I think two of the main characters are homosexual. They only went through the motions of finding a girlfriend because that is what they thought was expected of them. The third character was straight and actually come out as heterosexual.

There are many hints, but I think you can look at it either way. Either the whole thing was actually to find a girlfriend and have sex or it was a way to find oneself and know what the other really thought. It just depends on what you want to believe.

I just think they are gay, from what I interpret from the movie.

Hints

The main character says he likes women, but never actively participated in finding a girlfriend. Even argues with his friend, that instead of going out and finding a girlfriend, he was out with him (his friend) the whole three years. I would interpret this as he was kind of angry that he made his choice to be with his friend but didn’t know how to tell him. The whole going out and trying to find a girl was just an excuse to not seem weird. Or it could just be that he thought they would actually be able to find girlfriends hanging out together.

The whole time the overweight character, kept making references of being gay. Including the really big clue where he drew cocks (damn good scene, laughed my ass off). He also didn’t like his friend talking about the girl that he liked. I thought, because he secretly wanted his friend for himself. The only problem with the whole theory is that he really wanted to date Jules and felt sad when he thought he screwed it up.

The following scene after that could just be that they were telling each other that they were really good friends and that they will miss each other for the following few years. Or it could be that they told each other that they really did love each other, like homosexual love.

The ending was totally gay, when they finally fall in love with each other and realize that the girls they went after were just an excuse and they really did love each other this whole time. Just my opinion. I’m glad it was left open, because I would rather think that they were just really, really awesome friends and that is all they would ever be.

I still bet that if they made a sequel, it would be years after they threw their girlfriends away and become lovers.

Damn Good Movie

It was touching at times and better than some older “teen” movies. The Director and writer really knows what moments are funny to people and what moments are touching and thoughtful.

Possibly Related Posts:


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:


SQLite and classes

While working on the Sign In class, I realized that I have no idea how I’m going to work it. After creating the first class of which I tested the theory of my creation, I thought that if I kept adding functions to the class that it would eventually become as the old classes that I made in the game that failed because it couldn’t be extended any further. I do understand that there is no way, as of now, that I will be able to keep it all at one class which in turns has some automatic controls below it.

After I started to write about how I was going to do it, the idea came to me and I figured it out and I finished it with it being an awesome improvement over the old one I made last year. There are still a few changes I may make but right now I think it is all good.

Possibly Related Posts:


SQlite and PHP 5

I am kind of enjoying PHP 5 and SQLite, but I’m kind of mad that I can’t extend the class for my other classes. That won’t really be a big issue since I can still use the functions in any class I create. I also like the new mysqli class and that I can extend the class, it really helps out with automating some things.

Although what I want to do with SQLite is fairly basic, I will probably extend on it at an later time. I don’t know, it is fairly difficult to think that I won’t be able to use something like PHPmyAdmin to easily make changes. I’m sure some joe will come along and create it, but that is some ways off and the first implementation is going to suck. For somethings I like the fact that I won’t be able to use it since I will have some privacy when it comes to what is actually in the table. While somethings would be extremely easy to do with MySQL, my host doesn’t really like what I want to do and I don’t want to bog down their servers.

One thing that I was hoping I would be able to do is create a grid and assign people to a section of the grid. Eventually, the player will grow into someone elses section and have to battle that player to gain more land. This would be really difficult to do even with SQLite and I’m not sure how the implementation will exactly be and how it will work with the game. I may do some work after I finish everything else. I am kind of looking forward to using SQlite for AI. That will be exciting.

Possibly Related Posts: