Today, the PHP language is widespread, it is easy to learn and understand, and probably that is why it is so popular with novice programmers. Without PHP knowledge, do not fix the voting block on the site, do not edit the PHP template, do not insert a banner ad. Many go further and learn the language more deeply, because it is not only interesting, but also brings a steady income, the benefit of various sentences for PHP programmers is always in abundance.
But what to do if you want something more? If you are tired of writing the same type of classes for online casinos, poking around in the next customer's Joomla / Drupal / PHPBB?
I think that many people have thought to start writing Windows programs in their favorite PHP language, but as a rule, they don’t go further than searching the Internet and superficially studying such libraries as PHP-QT and PHP-GTK. Why? All answers are similar - confusing, complicated, incomprehensible, incomprehensible, etc. But today there is already a qualitatively new and promising environment for the visual development of programs for PHP under Windows and the name for it is PHP Devel Studio (abbr. DevelStudio).
What is DevelStudio?

')
This is a convenient and understandable visual programming environment that allows you to create full-fledged PHP programs with GUI support. Now, to create programs for Windows, it is enough to know the most popular programming language - PHP.
In this article I will not describe the buttons and thingies of this development environment, I will not talk about some abstract possibilities and I will not arrange a kindergarten with the writing “Hello world”.
We will superficially consider the process of writing a full-fledged program for Windows and will focus only on original and non-standard solutions that will definitely be interesting to everyone.
Prehistory
So, one fine evening, I again visited the Denwer project site again to check if there was an update. To my disappointment, there was nothing new there, as before, I found only a new abuse against developers with accusations of begging for donations and absolute inaction.
I didn’t want to refuse Denwer and write my own, really convenient and useful program for managing a local web server. After a brief search, my attention was drawn to the development environment “DevelStudio”. It turned out to be extremely convenient, understandable and the most surprising - it opened the way for me to the world of Windows programs. After thinking about the logic of managing the web server, I started writing "Open Server".
Meet DevelStudio
The first few days were spent studying the environment and writing the simplest programs. There were several bugs in the work of the development environment itself, they will be described at the end of the article. Two useful additions were also installed (a
library of examples + a
catalog of classes and functions ) and one
unofficial patch enabling the UPX program to be compressed by the packer at the time of compilation.
It should be noted that DevelStudio has a good enough community, so there is always the opportunity to ask a question or get advice from experienced users of the environment, right up to the developer.
DevelStudio is a mixture of Delphi and PHP, generously flavored with the components of these Delphi and PHP. What is only one
Alphaskin , which I used in the most direct way when writing a program. But first things first…
Writing a program
When creating a project, we get an empty form. It is the main one and it was in this form that I did not create any controls, I added control functions in it, and the form itself was made hidden. So that when you start your program does not display any forms in the project properties, you need to set the “Silent” mode. Then the following forms were created:
Settings, View logs, About the program, Error and First run . In a short time, the necessary controls, input fields, icons, and more were added to all forms. All this was done without a single line of code. Here it is the power of the visual environment!
In the following illustration, we see the form of viewing logs, as well as special insert templates, they are used to organize multilingualism. I note only that to change the language will need to restart the program.

Next, I started adding the first PHP code. As I already wrote, we will stop only on the most interesting moments.
1. Start function (executed when the program is loaded)
This is how it turned out to implement a check on whether the program has already been launched:
$output = shell_exec('tasklist /nh /fi "Imagename eq Open Server.exe"'); // $ret = iconv('CP866','CP1251',$output); if (substr_count($ret,'Open Server.exe')>1) { c('trayIcon1')->enabled = false; // - LoadForm(c('message'), LD_NONE); // }else{ ... }
So, for example, items are added to the drop-down menu:
$mm = new TMenuItem; $mm->caption = t("menu_9"); // t - , $mm->loadPicture("server/system/data/exit.bmp"); // $mm->onClick = exitfunc; // /
And this was the way to solve the problem of determining the bit rate of Windows and checking for the presence of installed Microsoft Redistributable C ++ components. For an hour I could not understand why in 32 and 64 bit versions of Windows registry keys have a different meaning, otherwise they are not at all where it was supposed to be.
if(getenv("PROCESSOR_ARCHITEW6432")=="AMD64" || getenv("PROCESSOR_ARCHITECTURE")=="AMD64"){ $output = shell_exec("REG QUERY HKLM\\Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); // $ret = iconv('CP866','CP1251',$output); if (substr_count($ret,'{86CE85E6-DBAC-3FFD-B977-E4B79F83C909}')<1 || substr_count($ret,'{a0fe116e-9a8a-466f-aee0-625cb7c207e3}')<1) { c('trayIcon1')->enabled = false; LoadForm(c('proc'), LD_NONE); // } }else{ $output = shell_exec("REG QUERY HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"); $ret = iconv('CP866','CP1251',$output); if (substr_count($ret,'{86CE85E6-DBAC-3FFD-B977-E4B79F83C909}')<1 || substr_count($ret,'{a0fe116e-9a8a-466f-aee0-625cb7c207e3}')<1 ) { c('trayIcon1')->enabled = false; LoadForm(c('proc'), LD_NONE); // } }
2. View logs form
It was all very simple here - reading the log file and outputting the content to a form, but I had to use a trick to automatically set the cursor to the end of the list (the
environment does not allow this ).

Here is how I initially processed switching tabs and setting the cursor to the end of the log:
$WshShell = new COM("WScript.Shell"); if (c("pages1")->pageIndex == 0) c("memo1")->setFocus(); // elseif (c("pages1")->pageIndex == 1) c("memo2")->setFocus(); ... elseif (c("pages1")->pageIndex == 6) c("memo7")->setFocus(); $WshShell->SendKeys("^{END}"); // END $WshShell->SendKeys("{HOME}"); // HOME
As we can see, COM components were used, but on the advice of a kind person, this code was turned into the following:
$ppindex = c("logs->pages1")->pageIndex; $obmemo = c("logs->memo".($ppindex+1)); // $cnlines = $obmemo->items->lines; // $seltn = strlen( $obmemo->text ) - strlen($cnlines[ count($cnlines)-1 ]); // $obmemo->setFocus(); $obmemo->selStart = $seltn; // $obmemo->selLength = 0; //
3. Settings form

Reading and writing settings in DevelStudio is quite simple and obvious:
ini :: open("server/system/config.ini"); // ini :: read("main", "lang", $lang); // ini :: write("main", "lang", c("settings->combobox1")->inText); //
But I had to tinker with something — getting a list of free disks in the system.
That's what happened first, it's quite interesting:
$fso = new COM("Scripting.FileSystemObject"); $disks = array(); foreach($fso->Drives as $disk) $disks[] = $disk->DriveLetter; // $diskarr = array("D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $diskar = array(); foreach($diskarr as $fffile) if($fffile == $os_vdisk){$diskar[] = $fffile;}else {if(!in_array($fffile,$disks)) $diskar[] = $fffile;} // , c("combobox2")->text = implode("\n",$diskar); $icounter = 0; foreach($diskar as $fffile) {if($fffile == $os_vdisk) c("combobox2")->itemIndex = $icounter; $icounter++;}
Here again, the COM component was used and again, it was not without good advice from outside.
I connected the phposinfo.dll DLL and the final code was like this:
$dliters = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); $diskar = array(); $icounter = 0; $icount = true; foreach ($dliters as $dliters) // { if ($dliters == $os_vdisk) { $diskar[] = $dliters; $icount = false; } else { if (osinfo_drivetype($dliters . ":") == 1) // phposinfo.dll { $diskar[] = $dliters; // if ($icount) $icounter++; } } } c("combobox2")->text = implode("\n", $diskar); // c("combobox2")->itemIndex = $icounter; //
4. Starting local server function
This is the most voluminous function, it was necessary to overwrite the configuration of the modules using templates, start a virtual disk, start Apache, Mysql, FTP server and write many more interesting things, however, here too DevelStudio and the environment support forum allowed me to realize everything that was planned. Next, some interesting points ...
There were problems with determining the system disk and getting the path to the HOSTS file, in the end everything turned out to be easy and simple:
$hostsfile = winLocalPath(CSIDL_WINDOWS) . "/System32/drivers/etc/hosts";
We start the virtual disk (the system utility subst.exe is used here, as well as getting the local directory and the path to the Windows system folder):
Shell_Execute(0, 'open', 'subst.exe', $os_vdisk . ': "' . substr(realpath('./'), 0, strlen(realpath('./')) - 1) . '"', strtr(winLocalPath(CSIDL_WINDOWS).'/System32/','/','\\'), 0);
Starting Apache (function Shell_Execute allows you to run a third-party program in the background and without waiting for a response):
Shell_Execute(0, 'open', 'os-httpd.exe', '', $realospath . '\\server\\http\\' . $os_httpdriver . '\\bin\\', $os_window);
I would like to especially note that one of the bugs of DevelStudio is a hangup when using background processes in Windows XP. Because of this, we had to make all processes non-background and, as a result, disable the tray menu at the time of starting / stopping the server. If this is not done, it may seem that the program is frozen, because at the moments of executing real-time processes, the controls do not react to anything.
To create a beautiful and identical looking in all versions of Windows tray menu, the Skin component was used, as well as one of the AlphaSkin skins, which I had previously edited.

After compiling the output, we get the usual executable EXE file, i.e. our program itself. PHP code is contained there in a binary compiled form, its decryption is impossible, which in principle allows you to write paid commercial software now. However, the conversion of PHP code to byte code (using BCompiler extension) can be disabled in the DevelStudio settings.
As you can see, with the help of PHP and DevelStudio I managed to realize all the tasks set before me. Not without calling the system utilities and built-in functions of the development environment. It turned out to be a full-fledged Windows program written in PHP, more precisely, even a complex of programs for organizing a web server on a local computer, now the Open Server project is living and successfully developing.
Present and Future of DevelStudio
Now DevelStudio is based on the PHP 5 engine, but the author is working hard to create a special branch of improved PHP - the so-called Orion engine, which will be used in DevelStudio from the next version. On the one hand, it is scary that no more updates from the original PHP will appear in the environment itself, except that it is already in the version of PHP that was chosen for the development of Orion. On the other hand, we would like to hope that the Orion engine will present us quite a few new goodies, but they promise a lot there:
Domestic developers Devel Studio, reported that their new development environment will soon begin to work with its own scripting programming language Orion, the syntax of which will combine the popular PHP + new language constructs.
It is also reported that for Devel Studio an abstract game engine is almost ready, which is based on ZenGL and Orion will be connected to it. GameAbstract Framework is an open gaming framework for fast and easy development of 2D games on Pascal (Delphi / FreePascal), Orion, and other YAN. Abstraction will allow developers to deal with the logic of the game, taking over the rest of the routine.
GameAbstract will allow you to create games on popular platforms: Windows, Linux, MacOS (and in the future iPhone / iPad). The developer will be free to choose a graphic interface: OpenGL, DirectX or OpenGL ES for mobile systems. Physics will be implemented on the basis of technology Chipmunk.
According to the site gcup.ru from 2011-05-23Conclusion
In general, DevelStudio left a good impression, then my modest conclusions.
Bugs:
- hang php program when using background processes in WinXP;
- background processes are not killed after processing (occupy memory);
- resizing not manually, but using more / less arrows leads to a crash;
- you cannot use the debug mode and error output, otherwise the changes are not saved;
- UPX packer does not work without patch;
Minuses:
- the presence of some bugs;
- the programs are quite voluminous, but when using UPX the difference is not so great;
- a larger amount of RAM occupied than a counterpart in Delphi or C ++;
- extremely poor official documentation, scarce and outdated;
Pros:
- ease of development and ease of development;
- good community;
- ample opportunities to use third-party libraries;
- high speed of program development;
- enjoyment of writing Windows programs in PHP ;-)
In my opinion, the DevelStudio visual development environment is another step towards blurring the boundaries between the choice of the development language for Windows programs. Write useful programs, develop and do not be afraid to experiment!
Useful links:
PHP Devel Studio Development EnvironmentLocal Open Server Web ServerUP: How do you hate so much? This is just another way to use the PHP language. Quite an interesting development environment, at least in terms of self-development. Nobody says that you need to drop everything and sit down to write Windows programs in PHP.
Just ask yourself a question - if you knew that your car can not only drive, but also fly, wouldn't it be interesting to you? Oh yeah, because there are planes for flights, aren't you ...