The core elements
So, why the core code of SKY. has a form presented here? Is it good or bad? Only time can give the correct answer to this question. The lifetime of the SKY. project once a considerable number of programmers will get acquainted with it, and your personal time, dear reader, which you will give to the SKY. project and analyze yourself everything it has. In the project we are putting and will put every effort and means to make this code ideal! Let's begin from the beginning: should the ideal code be simple enough for the overwhelming majority of Web developers to easily take advantage of it with little or no reading documentation and still being very effective; is it possible? The answer to both questions: Yes! Simple code is the first and most important rule in SKY. Moreover, there can be only one perfect code, a priori, and we are looking for it in the SKY. project.
Reflections when creating the core code are as follows: we will need a reusable code (1 file - main/sky.php), which you can always run, from any point of entry. It will initiate a connection to the main database, will include a wrapper function sql() to make requests to the database. All requests going through this function will automatically get into the trace buffer. We need a trace function and our own error handler, which will request a trace function with the option "show error". We need a class of SKY. that will contain the data register, configuration data memory, as well as other useful features. Let's call file main/sky.php the first wing file, as it will be run for all entry points.
For the front-end and admin entry points we will create the file main/wings.php, it will contain a standard reusable code for user sessions, user registration, and any other code. This is the code of the second wing, as it is used in more than one entry points.
We will also create a file main/front.php, this file will be used only for a single point of entry - front, so, this is the code of the third wing, as the code in the main/cron.php file - to run from the entry point cron.
CORE ADDRESSING SYSTEMQueries to the admin section:
where /adm specifies the access to the admin section, a page indicates the executable file in the admin folder, i.e. admin/_page.php, in the file .htaccess the query is redirected to the index.php file. From this file, the admin router is activated - admin/index.php. Queries to the front section:
Thus, if we assume that general addressing (the most flexible) includes: the protocol, the domain name, the folder address, the file and QS (query string, keys with values, for example,?qq=ww&rr=tt), then the main system of addressing of SKY. applications prohibits the use of "folder address" part (the the use of symbol of folders demarcation "/") that allows you to use relative addressing to images and other addresses in view-files. It greatly simplifies the coding of queries, the size of the generated HTML file. Also it becomes possible not to create a separate virtual server for each project, but to create new projects just in the folder of the same virtual server on a developer's workstation (all SKY. applications must remain operable when placing them in a folder of the virtual server). For example,
Let us note, just for the fun of it, that constant PATH (see the file main/wings.php) in the given example will contain /project3/.In SKY. we introduced abstract variables PAGE, PVAL, WHAT, WVAL that correspond to the parts of a query - the first key and a value, and also the second. The first variable identifies the respective page that corresponds to the file-processor or controller (for MVC).
AJAX FUNCTIONALITYUsually to execute an ajax query, you need to do a lot of formal actions, so in order not to do them (to make it easy) in SKY. we introduced a function ajax (..) in the file pub/wings.js. When you use it, you do not need to write the address of the file handler, as it provides a part of the current page address (retrieves it from document.location.href), i.e. (in the case of MVC) a query goes to "your" controller, and only a pseudo name of the handler method is indicated. The function has also pre-defined the use of the POST method, as much more often AJAX functionality requires the absence of browser-caching. Besides, the address generated for the real access to the server includes a standard part for this functionality - AJAX key:
http://mysite.net/index.php?AJAX=page&page=pval (pval - controller method for MVC)
http://mysite.net/index.php?AJAX=adm&page=pval (ajax query to the admin section)
http://mysite.net/index.php?_=adm&page=pval (plain, not ajax query to the the admin section is run by MOD_REWRITE)
that sets the PHP constant of AJAX at non-zero value, i.e. already in the reusable code of the first wing there is information on the standard AJAX query that allows, for example, to automatically disable LAYOUT for this query, and write the trace data into the database (and not to make output into STDOUT).
BUFFERING OF STDOUTPHP "echo 'z';" code puts conditionally one byte of "z" in the browser, but in really, it practically never happens, but instead, there is a record to the system buffer and only after reaching the "right portion" of the data the real data transfer happens across the network. STDOUT buffering is the fundamental mechanism for significant performance improvement when transmitting data over the network and normal functioning of all computers and network devices. The logics of buffering is as follows: the packets in the network have a part of proprietary information and a part of useful information, and network performance can be practically achieved when the quantity of useful information goes beyond the informational part (HEADER) in a certain number of times, that is the packet is not small (in order not to transmit a large number of headers) but it is not big either (to send information from one side to the receiver as quickly as possible, on the one hand, and on the other hand, - to make it easier to fix faulty packets of not very large volume). On the other hand, when transmitting very large pages, you need to save a server memory, and for each client (which is connected in parallel) a small volume of memory can be allocated, compared to the volume of the whole page transmitted to him. Thus, the fundamental logics of building modern networks determines the need for buffers for different protocols of the higher level, for example HTTP. Moreover, we need to emphasize that this function is associated with the hardware parts of the networks, which existance is potentially more stable than the existence of any software. Thus, we can consider buffering to be a de facto functional, which cannot be doubted.
The existence of STDOUT buffering de facto allows you to create an additional "delicious" functional of tags. Delicious is when significant system resources allocated for one purpose, can be used simultaneously for another purpose without additional significant resources. Tags is something that you have to find and replace with something different. It is for example the whole text of the HTML page, which is compressed to a smaller size with compression modules; this is conversion of all national symbols of the HTML page into a different encoding, or replacement of the tag-identifier used in SKY. with the corresponding HTML image.
Tags also let you implement a functional of "tight" caching, which can improve the code effeciency. For example, consider this code:
...some HTML before <?cache('right_col')?> <!-- BEGIN CACHE AREA --> <td> %PHP_RIGHT% </td> <?cache()?> <!-- END CACHE AREA --> ...some HTML after
In this example, the tag %PHP_RIGHT% (recognized with regular expression) triggers the PHP code of the tag to get the display. If the tag % PHP_RIGHT% generates the content of the right column of the site and instant relevance of its display is not of immediate interest (as it happens quite often), then this content may be cached and updated only once every 5 minutes, for example. Fully generated right column is recorded into the file cache/right_col.html. During the execution of the function cache ('right_col'), it is checked: if the above file is fresh, then the PHP code of the tag is not run at all, and the display is taken from the cache file. Such caching might disable the execution of several SQL queries and PHP code that generates the content of the right column in general, and significantly improve the efficiency of the site code. In this case, the tag, in addition to the service value also gets a functional one.
Negative points of tags functional: First of all, you must not forget to convert the data received from the site users and your own data containing a percent sign % (which may be interpreted as a frame of a tag) into equivalent HTML entities - %, otherwise there could be an attack linked to the generation of unnecessary tags or there may be your own errors associated with this, that is why the code of the first and second wings have the appropriate corrections, see. for example, the code main/sky.php, function html(..).
Secondly, unfortunately, in PHP, a functional related to the operation of STDOUT buffers is extremely poorly implemented and confused. Instead of multiple functions of the family ob_.. ob_get_clean, ob_end_flush, etc, it was necessary to make one function ob_action with keys-constants OB_FLUSH, OB_GET, OB_CLEAN, OB_END, as well as OB_REPLACE (replacement of the buffer contents without the fact of resetting or emptying), OB_CALLBACK - indication of whether to call the callback function and a conditional resetting, emptying, etc.. For example, when reaching 4096 bytes for resetting, the callback function is invoked and it is validated whether all tags pending values are calculated (the other types can be calculated at the current stage). If "Yes", then a network packet is sent to the browser. If "No" - buffering continues. This would make it possible to use 100% computer power in this aspect. It is also necessary for the first level of buffering to be virtual, i.e., on the first call to ob_start() function the system buffer must be used, and the memory would not be allocated specifically for it, and in the callback function the buffer would be passed by the reference.