GithubHelp home page GithubHelp logo

indeyets / appserver-in-php Goto Github PK

View Code? Open in Web Editor NEW
292.0 13.0 22.0 981 KB

Generic HTTP applications approach for PHP5.3+ (inspired by Rack and WSGI)

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%

appserver-in-php's Introduction

AppServer, a set of components for building fast universal web-apps in PHP

Latest Stable Version

Web server interface for PHP, inspired by Ruby’s Rack and Python’s WSGI. It provides a common API for connecting PHP frameworks and applications to webservers.

The main idea is, that your app, if built for this protocol, will be able to preload resources, preconnect to databases and response to requests really fast.

PHP 5.3+ is required, as it provides garbage collector for cyclic references, which is critical for long-running apps.

Installation

The recommended way to install AiP is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:

{
    "require": {
        "aip/aip": "~0.10.0"
    }
}

Usage

Take a look at example.

  • MyApp.class.php — application class. "__invoke()" method is the entry point
  • aip.yaml — defines that this application should be served both as HTTP and SCGI

run with aip app [path/to/[aip.yaml]] command, test by pointing your browser to http://127.0.0.1:8080/

##Discuss

Please join our discussion group

There's also #appserver-in-php IRC-channel on freenode

appserver-in-php's People

Contributors

bergie avatar indeyets avatar jaypea avatar saleemkce avatar umonkey avatar zozfried avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appserver-in-php's Issues

Failed to flush session data

I'm trying to use AiP with Windows (of course not as a real application server). For this my mod_php will just fire up a PHP script that sets up the autoloading, instantiates my app server class (the same AiP would fire up) and invoke it with some context data.

This works really well, except for the sessions. Sessions cannot be saved and I get the PHP error

Warning: file_put_contents(): Only 0 of 85 bytes written, possibly out of free disk space

Disk space is OK. I can write to the file in question without any problems. Even from PHP, even from the same script and same request. The problem is the file locking, which uses LOCK_EX. If I add LOCK_SH, session files are written and the problem goes away.

<?
// AiP/Middleware/Session/Storage/FileStorage.php, line 140
flock($this->_fp, LOCK_EX | LOCK_SH);

I'm no expert on file locking, so I can't recommend this as a general solution (that's why I didn't create a pull request). If however it's no problem for *nix systems to have the LOCK_SH flag set, I would greatly appreciate having it in there.

In the meantime, I just use a patched version for Windows systems. Since I cannot use Composer to install AiP (requires posix and pcntl extensions), I have to install the vendor stuff by extracting a zip file anyway. So it's not super urgent to be fixed.

Namespace imports must use fully qualified names

http://php.net/manual/en/language.namespaces.importing.php

"Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar), the leading backslash is unnecessary and not allowed, as import names must be fully qualified, and are not processed relative to the current namespace. "

I've ran into a real manifestation of this, because Transport/Socket.php uses Transport/Socket/RuntimeException, but the autoloader can't find it, because the namespace of the requester file isn't passed to the autoloader. So one must use fully-qualified names.

HTTP connector

We need HTTP/1.0 connector. This way it will be possible to run applications locally without need for additional server-software and to use HTTP-proxy servers (such as squid) as a mean of deployment

What next?

I have installed appserver-in-php and started the appserver per instructions.

root@AIP:/var/www/html/aip# ./bin/aip app examples/new/aip.yaml
Loading configuration…
[app+] MyApp server via HTTP at tcp://127.0.0.1:8080. (5-10 workers)
[app+] MyApp server via SCGI at tcp://127.0.0.1:9999. (1-2 workers)
Starting workers…

I have hit the URL:
http://x.x.x.x/aip/examples/new/template.html

I have tried entering various inputs. No indication of anything functioning or results returned.

What next?

Thank You

Compress middleware doesn't support streams

When using the FileServe app with the Compress middleware I get the following exception:

PHP Warning: gzdeflate() expects parameter 1 to be string, resource given in /opt/local/lib/php/AiP/Middleware/Compress.php on line 31
PHP Stack trace:
PHP 1. {main}() /opt/local/bin/aip:0
PHP 2. pakeApp->run() /opt/local/bin/aip:9
PHP 3. pakeApp->initAndRunTask() /opt/local/lib/php/pake/pakeApp.class.php:149
PHP 4. pakeTask->invoke() /opt/local/lib/php/pake/pakeApp.class.php:246
PHP 5. pakeTask->execute() /opt/local/lib/php/pake/pakeTask.class.php:186
PHP 6. call_user_func_array() /opt/local/lib/php/pake/pakeTask.class.php:223
PHP 7. AiP\Runner\App::run_app() /opt/local/lib/php/pake/pakeTask.class.php:0
PHP 8. AiP\Runner->go() /opt/local/lib/php/AiP/Runner/App.php:96
PHP 9. AiP\Runner->startWorker() /opt/local/lib/php/AiP/Runner.php:29
PHP 10. AiP\Runner->worker() /opt/local/lib/php/AiP/Runner.php:77
PHP 11. AiP\Handler\Daemonic->serve() /opt/local/lib/php/AiP/Runner.php:113
PHP 12. AiP\Transport\Socket->loop() /opt/local/lib/php/AiP/Handler/Daemonic.php:64
PHP 13. call_user_func() /opt/local/lib/php/AiP/Transport/Socket.php:31
PHP 14. AiP\Handler\Daemonic->onRequest() /opt/local/lib/php/AiP/Transport/Socket.php:0
PHP 15. call_user_func() /opt/local/lib/php/AiP/Handler/Daemonic.php:87
PHP 16. AiP\Middleware\Logger->__invoke() /opt/local/lib/php/AiP/Handler/Daemonic.php:0
PHP 17. call_user_func() /opt/local/lib/php/AiP/Middleware/Logger.php:59
PHP 18. AiP\Middleware\Compress->__invoke() /opt/local/lib/php/AiP/Middleware/Logger.php:0
PHP 19. gzdeflate() /opt/local/lib/php/AiP/Middleware/Compress.php:31

Warning: gzdeflate() expects parameter 1 to be string, resource given in /opt/local/lib/php/AiP/Middleware/Compress.php on line 31

Call Stack:
0.0002 630136 1. {main}() /opt/local/bin/aip:0
0.0071 1887344 2. pakeApp->run() /opt/local/bin/aip:9
0.0081 2037696 3. pakeApp->initAndRunTask() /opt/local/lib/php/pake/pakeApp.class.php:149
0.0082 2041480 4. pakeTask->invoke() /opt/local/lib/php/pake/pakeApp.class.php:246
0.0082 2041480 5. pakeTask->execute() /opt/local/lib/php/pake/pakeTask.class.php:186
0.0084 2042608 6. call_user_func_array() /opt/local/lib/php/pake/pakeTask.class.php:223
0.0084 2042648 7. AiP\Runner\App::run_app() /opt/local/lib/php/pake/pakeTask.class.php:0
0.0159 2621928 8. AiP\Runner->go() /opt/local/lib/php/AiP/Runner/App.php:96
0.0197 2750440 9. AiP\Runner->startWorker() /opt/local/lib/php/AiP/Runner.php:29
0.0298 2750488 10. AiP\Runner->worker() /opt/local/lib/php/AiP/Runner.php:77
0.0386 3568136 11. AiP\Handler\Daemonic->serve() /opt/local/lib/php/AiP/Runner.php:113
0.0387 3568136 12. AiP\Transport\Socket->loop() /opt/local/lib/php/AiP/Handler/Daemonic.php:64
1.9608 3568896 13. call_user_func() /opt/local/lib/php/AiP/Transport/Socket.php:31
1.9608 3568928 14. AiP\Handler\Daemonic->onRequest() /opt/local/lib/php/AiP/Transport/Socket.php:0
1.9615 3583256 15. call_user_func() /opt/local/lib/php/AiP/Handler/Daemonic.php:87
1.9615 3583288 16. AiP\Middleware\Logger->__invoke() /opt/local/lib/php/AiP/Handler/Daemonic.php:0
1.9617 3584768 17. call_user_func() /opt/local/lib/php/AiP/Middleware/Logger.php:59
1.9617 3584800 18. AiP\Middleware\Compress->__invoke() /opt/local/lib/php/AiP/Middleware/Logger.php:0
1.9645 3780560 19. gzdeflate() /opt/local/lib/php/AiP/Middleware/Compress.php:31

PHP Notice: Undefined variable: len in /opt/local/lib/php/AiP/Middleware/Logger.php on line 71
PHP Stack trace:
PHP 1. {main}() /opt/local/bin/aip:0
PHP 2. pakeApp->run() /opt/local/bin/aip:9
PHP 3. pakeApp->initAndRunTask() /opt/local/lib/php/pake/pakeApp.class.php:149
PHP 4. pakeTask->invoke() /opt/local/lib/php/pake/pakeApp.class.php:246
PHP 5. pakeTask->execute() /opt/local/lib/php/pake/pakeTask.class.php:186
PHP 6. call_user_func_array() /opt/local/lib/php/pake/pakeTask.class.php:223
PHP 7. AiP\Runner\App::run_app() /opt/local/lib/php/pake/pakeTask.class.php:0
PHP 8. AiP\Runner->go() /opt/local/lib/php/AiP/Runner/App.php:96
PHP 9. AiP\Runner->startWorker() /opt/local/lib/php/AiP/Runner.php:29
PHP 10. AiP\Runner->worker() /opt/local/lib/php/AiP/Runner.php:77
PHP 11. AiP\Handler\Daemonic->serve() /opt/local/lib/php/AiP/Runner.php:113
PHP 12. AiP\Transport\Socket->loop() /opt/local/lib/php/AiP/Handler/Daemonic.php:64
PHP 13. call_user_func() /opt/local/lib/php/AiP/Transport/Socket.php:31
PHP 14. AiP\Handler\Daemonic->onRequest() /opt/local/lib/php/AiP/Transport/Socket.php:0
PHP 15. call_user_func() /opt/local/lib/php/AiP/Handler/Daemonic.php:87
PHP 16. AiP\Middleware\Logger->__invoke() /opt/local/lib/php/AiP/Handler/Daemonic.php:0

Notice: Undefined variable: len in /opt/local/lib/php/AiP/Middleware/Logger.php on line 71

Call Stack:
0.0002 630136 1. {main}() /opt/local/bin/aip:0
0.0071 1887344 2. pakeApp->run() /opt/local/bin/aip:9
0.0081 2037696 3. pakeApp->initAndRunTask() /opt/local/lib/php/pake/pakeApp.class.php:149
0.0082 2041480 4. pakeTask->invoke() /opt/local/lib/php/pake/pakeApp.class.php:246
0.0082 2041480 5. pakeTask->execute() /opt/local/lib/php/pake/pakeTask.class.php:186
0.0084 2042608 6. call_user_func_array() /opt/local/lib/php/pake/pakeTask.class.php:223
0.0084 2042648 7. AiP\Runner\App::run_app() /opt/local/lib/php/pake/pakeTask.class.php:0
0.0159 2621928 8. AiP\Runner->go() /opt/local/lib/php/AiP/Runner/App.php:96
0.0197 2750440 9. AiP\Runner->startWorker() /opt/local/lib/php/AiP/Runner.php:29
0.0298 2750488 10. AiP\Runner->worker() /opt/local/lib/php/AiP/Runner.php:77
0.0386 3568136 11. AiP\Handler\Daemonic->serve() /opt/local/lib/php/AiP/Runner.php:113
0.0387 3568136 12. AiP\Transport\Socket->loop() /opt/local/lib/php/AiP/Handler/Daemonic.php:64
1.9608 3568896 13. call_user_func() /opt/local/lib/php/AiP/Transport/Socket.php:31
1.9608 3568928 14. AiP\Handler\Daemonic->onRequest() /opt/local/lib/php/AiP/Transport/Socket.php:0
1.9615 3583256 15. call_user_func() /opt/local/lib/php/AiP/Handler/Daemonic.php:87
1.9615 3583288 16. AiP\Middleware\Logger->__invoke() /opt/local/lib/php/AiP/Handler/Daemonic.php:0

Standardization of loader and layout of catalogues

Hello,

I would like to propose a new layout of catalogues which will be adapted to the class SplClassLoader: http://github.com/metagoto/splclassloader (which will be implemented in PHP in the near future). Then layout of catalogues would change on that:

--bin

----aip (actually /Runner/bin/aip)

--library

-----MFS

--------AppServer

-----------iProtocol (maybe Protocol?)

--------------HTTP

-----------------Server.php

--------------SCGI

-----------------Server.php

-----------------Client.php

-----------------Response.php

...etc...

Regards
deallas

Graceful restart of the aip app

Hi Alexey,

Hope you are doing well.

I and starting my app with

aip app somefile.yaml

Is there a possibility to implement

aip app somefile.yaml graceful (similar to apachectl graceful)

method which will restart all the children once they have finished doing the current task?

For the older projects I am using a very old version of AIP with homegrown stop handlers for each process that is listening on a specific port (one process per port).

I want to use now for the next project the official version with multiple processes on the same port and let AIP take care of the loadbalancing of the processes than use an external loadbalancer.

Let me know if you need my help.

kind regards.

Atif

File uploads broken by escaping introduced for file fields named myField[abc][xyz]

Hi,

Having a go with this and loving the speed boost.

Found that the following breaks upload fields with simple names:

$sel = preg_replace('/([^[]]+)/', ''\1'', $disposition['name']);

(which is around line 206 or so of /Middleware/PHP_Compat/PHP_Compat.class.php)

In the case of a field named simply, for example, 'upload', the field has its key in the $_FILES array set as 'upload' (i.e including the single quotes).

Advanced file-uploads middleware(s)

Quoting PAStheLoD:

Hi, please consider the issue of input buffering, especially in the case of handling large file uploads. (And trying to show the user transfer the speed for example.)

Also the request parsing should be able to deal with this. (So, for example, via inheriting from a specific class, one could work together with AiP's request handler to set up where to save the files, put stats into memcache or APC cache, or filter on filename, or inspect the beginning of files for some MIME magic.)

Middleware/HTTPParser: Cannot re-assign auto-global variable _POST

AiP in MeeGo Apps produces a fatal error when starting:
Fatal error: Cannot re-assign auto-global variable _POST in /usr/share/php/AiP/Middleware/HTTPParser.php on line 91

Environment: Debian unstable (x86_64 arch)

$ php -v
PHP 5.4.4-7 (cli) (built: Aug 30 2012 08:57:09)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

FastCGI connector

We need a FastCGI connector. FastCGI support is more widely available than SCGI support and protocol is more capable in general (multiplexing support).

The plan is to implement FastCGI connector using php's fastcgi library (fastcgi library -> pecl/fastcgi -> fastcgi connector)

Tag a new release

As with pake, a new release would come handy for users without git on their machines.

I assume you are going to tag soon anyway, so this is just a reminder :-)

PEAR repository

Hi,

The PEAR repo seems to have been pretty much abandoned in favour of Composer. If that's the case it would be good if it were marked as such. Even better would be to keep it up to date of course as Composer isn't appropriate for everyone.

Cheers

Consider opening the API

I'm trying to work around issue #23. For this, I tried to simply use a custom storage implementation that has my patch (LOCK_SH) in it.

Unfortunately, nearly everything inside the Session middleware is private, so for making a simple patch to lock() I have to copy nearly everything. Not just because most of the stuff is private, but because most methods directly access the properties (instead of using a getter).

This makes it extremely hard and ugly to subclass AiP. I would suggest using protected more often and/or introducing some getters where properties must be private.

Unable to run /vendor/bin/aip

After running composer install I try to run vendor/bin/aip app mongrel2.yaml in the application's root. It ends up with this error message:

/vendor/bin/aip: @PHP-BIN@: bad interpreter: No such file or directory

Seems to be some token @PHP-BIN@ there that wasn't exchanged with the correct value?

Error when installing via composer

Hi Alexey,
I have just installed via composer and try to run my app.
Here is what I am getting. Can you please addd them as dependencies in your composer definition file.
thanks

ponyo-mba~/www/worldsoft/projects/ws_wbs/wbs_backend> /usr/local/bin/php -v
PHP 5.4.19 (cli) (built: Sep 18 2013 11:14:22)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

ponyo-mba~/www/worldsoft/projects/ws_wbs/wbs_backend> /usr/local/bin/php vendor/bin/aip app aip.dev.yaml
Loading configuration…
PHP Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /Users/aghaffar/www/clients/worldsoft/projects/ws_wbs/wbs_backend/vendor/aip/aip/AiP/Runner/AppCommand.php on line 40

Fatal error: Class 'Symfony\Component\Yaml\Yaml' not found in /Users/aghaffar/www/clients/worldsoft/projects/ws_wbs/wbs_backend/vendor/aip/aip/AiP/Runner/AppCommand.php on line 40

Notice: fwrite(): send of 1024 bytes failed with errno=32

Lots of these notices in console while running appserver. I'm not really sure if they affect performance in anyway, but there seems to be some random crashes and this propably should be investigated.

Notice: fwrite(): send of 1024 bytes failed with errno=32 Broken pipe in /usr/share/php/AiP/Protocol/HTTP.php on line 159

Call Stack:
0,0031 642704 1. {main}() /usr/bin/aip:0
0,0218 2053416 2. pakeApp->run() /usr/bin/aip:9
0,0242 2222504 3. pakeApp->initAndRunTask() /usr/share/php/pake/pakeApp.class.php:149
0,0244 2227912 4. pakeTask->invoke() /usr/share/php/pake/pakeApp.class.php:246
0,0244 2227912 5. pakeTask->execute() /usr/share/php/pake/pakeTask.class.php:186
0,0247 2229584 6. call_user_func_array() /usr/share/php/pake/pakeTask.class.php:223
0,0247 2229656 7. AiP\Runner\App::run_app() /usr/share/php/pake/pakeTask.class.php:0
0,0370 2855160 8. AiP\Runner->go() /usr/share/php/AiP/Runner/App.php:96
0,0396 2997728 9. AiP\Runner->startWorker() /usr/share/php/AiP/Runner.php:29
0,0559 2997808 10. AiP\Runner->worker() /usr/share/php/AiP/Runner.php:77
0,4001 4544392 11. AiP\Handler\Daemonic->serve() /usr/share/php/AiP/Runner.php:113
0,4001 4544392 12. AiP\Transport\Socket->loop() /usr/share/php/AiP/Handler/Daemonic.php:64
3756,6053 41709480 13. call_user_func() /usr/share/php/AiP/Transport/Socket.php:31
3756,6053 41709544 14. AiP\Handler\Daemonic->onRequest() /usr/share/php/AiP/Transport/Socket.php:0
3756,6172 41736944 15. AiP\Protocol\HTTP->writeResponse() /usr/share/php/AiP/Handler/Daemonic.php:93
3756,6193 41738696 16. AiP\Protocol\HTTP->write() /usr/share/php/AiP/Protocol/HTTP.php:39
3756,6193 41738776 17. fwrite() /usr/share/php/AiP/Protocol/HTTP.php:159

debugging the 'app' running in your appserver

I have been assigned the task of writing some tests for a Drupal APP running on top of your appserver.

If xdebug were to be installed on the base PHP, would I be able to set breakpoints, etc in the APP running in your appserver? Since I do not control the dev server, I can't just 'try it'. :) If I 'should' work, I will request to have xdebug installed.

Thank You

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.