venkatiiitb / phpdesktop

Automatically exported from code.google.com/p/phpdesktop
0 stars 0 forks source link

Embed PHP interpreter through PHP API, a replacement for CGI #3

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently we are running php web-server at http://127.0.0.1:54007/, the 
downside of it is that it can cause some troubles with firewalls, when running 
application they they may ask user whether this application is allowed to 
listen at 127.0.0.1 on port 54007.

We should make this an option whether we want to act as a web-server or execute 
scripts directly by running command "php.exe -f myscript.php".

The possible advantage of running as a webserver might be a better performance, 
but there is only one user connecting to that web-server in our case, so the 
gain is dubious.

Original issue reported on code.google.com by czarek.t...@gmail.com on 13 Jan 2013 at 1:15

GoogleCodeExporter commented 9 years ago
Running "php.exe -f myscript.php" does resolve the firewall issue, as executing 
such command will also cause a firewall prompt. The ideal solution is to 
execute PHP script through PHP API, in PHP binaries there is a "dev/php5.lib" 
file, it looks like a static lib for the php5.dll, what we need is a php5.h 
header so we can call PHP API directly through php5.dll with no need to execute 
php5.exe. There seems to be no single "php5.h" file, it is probably required to 
download all sources codes of php5 from here:
http://windows.php.net/download/#php-5.4 > "Download source codes".

Original comment by czarek.t...@gmail.com on 13 Jan 2013 at 2:46

GoogleCodeExporter commented 9 years ago
This will not work, unless we can implement a custom scheme,
without it we have no way to listen for coming requests.

Implementing a custom scheme is possible with Chrome, I'm not
sure about Internet Explorer, this feature will probably be
implemented only for Chrome.

Original comment by czarek.t...@gmail.com on 13 Jan 2013 at 6:24

GoogleCodeExporter commented 9 years ago
When executing php script directly how do we set the document root?

Original comment by czarek.t...@gmail.com on 14 Jan 2013 at 8:51

GoogleCodeExporter commented 9 years ago
The source of the "php.exe" can be found in sapi/cli/php_cli.c, function that 
interests us is "php_execute_script":

https://github.com/php/php-src/blob/master/sapi/cli/php_cli.c#L988

Original comment by czarek.t...@gmail.com on 15 Jan 2013 at 5:08

GoogleCodeExporter commented 9 years ago
Calling PHP API directly would require implementing multi-threading
if we want to support handling multiple requests at the same time.
PHP built-in webserver is also single threaded, it cannot handle more
than one request at the same time, see Issue 14.

Original comment by czarek.t...@gmail.com on 15 Jan 2013 at 5:27

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
We will still need a web-server, otherwise submitting forms and uploading files
won't work. The solution would be to implement a virtual file system (VFS) in 
the
mongoose web-server. Or maybe PHP API already has a VFS mechanism?

Original comment by czarek.t...@gmail.com on 2 Feb 2013 at 3:38

GoogleCodeExporter commented 9 years ago
VFS in mongoose web-server is not enough, as php scripts include other php
scripts, so it must be some kind of VFS in PHP API.

Original comment by czarek.t...@gmail.com on 2 Feb 2013 at 3:53

GoogleCodeExporter commented 9 years ago
We need VFS in both Mongoose & PHP API.

Original comment by czarek.t...@gmail.com on 2 Feb 2013 at 3:56

GoogleCodeExporter commented 9 years ago
To use an in-memory file system in Mongoose web-server you have to
implement "open_file" callback, example here:

https://github.com/valenok/mongoose/blob/ee55d38b5592cbb55b78c74c2c36fc768fc22a0
7/test/unit_test.c#L192

Original comment by czarek.t...@gmail.com on 2 Feb 2013 at 5:29

GoogleCodeExporter commented 9 years ago
See this topic for an in-memory filesystem with Mongoose:
https://groups.google.com/d/topic/mongoose-users/JhNQFKC_0wI/discussion

Original comment by czarek.t...@gmail.com on 2 Feb 2013 at 5:57

GoogleCodeExporter commented 9 years ago
See Kroll's PHP module:
https://github.com/appcelerator/kroll/tree/master/modules/php

Original comment by czarek.t...@gmail.com on 4 Feb 2013 at 4:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
When PHP is run in other way than through CGI, memory leaks might be a problem.

Original comment by czarek.t...@gmail.com on 13 Feb 2013 at 6:11

GoogleCodeExporter commented 9 years ago
This is not a good idea to execute PHP using the PHP API, as PHP was never 
intended to run long hours and this could result in memory leaks.

Original comment by czarek.t...@gmail.com on 19 Jan 2014 at 7:24