Code Monkey home page Code Monkey logo

Comments (28)

ruudk avatar ruudk commented on May 17, 2024 1

The Symfony example is not performant at all. It's doing a $kernel->reboot(null); after every request. Is that really necessary? Why not just do $kernel->boot(); before the while loop, and then process all the requests without rebooting? Makes it much faster.

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024 1

Wasn't this fixed with resettable services?

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Done! https://github.com/spiral/roadrunner/wiki/Symfony-Framework Let me know if you want to change something in the article. I wonder if GitHub has any protocol for Wiki PRs.

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

FYI, you can define ENV in env section of config, these variables would be PHP process specific.

from roadrunner.

dunglas avatar dunglas commented on May 17, 2024

Thanks @wolfy-j. Indeed env vars should probably be moved here. I'll send you the changes when ready.

from roadrunner.

mnavarrocarter avatar mnavarrocarter commented on May 17, 2024

@dunglas I was using your config in my SF 4.1 app, but my static files like (app.js and images) could not be loaded. Switched to php -S 0.0.0.0:8000 -t public/ and worked. ยฟDo you have any idea or suggestions for finding the issue?

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Have you changed static.dir option to reflect your directory structure?

static:
  dir:   "public"
  forbid: [".php", ".htaccess"]

Also, try to run with -d flag to see what RR debug log says. Most likely your public directory path is invalid (though you must get an error if the path does not exist).

from roadrunner.

mnavarrocarter avatar mnavarrocarter commented on May 17, 2024

Yeap, the folder is pointing to the right direction and exists. Running with -d flag shows no output. The error happens at browser level when tries to load the js.

image

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Does -d show any other requests coming to RR?

It should look like that: http://prntscr.com/l1atdz

from roadrunner.

mnavarrocarter avatar mnavarrocarter commented on May 17, 2024

Yeap, and found the assets ones. They are answered with 404s.

image

from roadrunner.

mnavarrocarter avatar mnavarrocarter commented on May 17, 2024

Yeah, found it. Is passing the requests for files directly to the application.

from roadrunner.

mnavarrocarter avatar mnavarrocarter commented on May 17, 2024

Daaang I'm stupid! The static config was not properly indented.

Sorry for wasting your time @wolfy-j . I'm loving the project already!! :)

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

This is correct behavior if file not found or static service is disabled (identical to nginx try_files).

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Daaang I'm stupid! The static config was not properly indented.

Sorry for wasting your time @wolfy-j . I'm loving the project already!! :)

Ugh, yaml is really annoying sometimes. Try using json config instead if you run into this problem often. :)

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

I just tried this example, but it doesn't work. I get this error: worker error: invalid prefix (checksum)
This is shown in my PHP error output:

[05-Oct-2018 09:50:32 UTC] PHP Fatal error:  Uncaught ErrorException: Warning: unpack(): Type C: not enough input, need 1, have 0 in /var/www/app/vendor/spiral/goridge/php-src/StreamRelay.php:110
Stack trace:
#0 /var/www/app/vendor/spiral/goridge/php-src/StreamRelay.php(76): Spiral\Goridge\StreamRelay->fetchPrefix()
#1 /var/www/app/vendor/spiral/roadrunner/src/Worker.php(51): Spiral\Goridge\StreamRelay->receiveSync(NULL)
#2 /var/www/app/vendor/spiral/roadrunner/src/Worker.php(56): Spiral\RoadRunner\Worker->receive(Array)
#3 /var/www/app/vendor/spiral/roadrunner/src/PSR7Client.php(45): Spiral\RoadRunner\Worker->receive(Array)
#4 /var/www/app/worker.php(51): Spiral\RoadRunner\PSR7Client->acceptRequest()
#5 {main}
  thrown in /var/www/app/vendor/spiral/goridge/php-src/StreamRelay.php on line 110

When I change the while loop to this:

while ($req = $psr7->acceptRequest()) {
    try {
        $resp = new \Zend\Diactoros\Response();
        $resp->getBody()->write("hello world");

        $psr7->respond($resp);
    } catch (\Throwable $e) {
        $psr7->getWorker()->error(get_class($e));
        $psr7->getWorker()->error((string)$e);
    }
}

it works fine.

Something is happening inside $response = $kernel->handle($request); that breaks.

What am I doing wrong?

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Do you echo anything to STDOUT without buffers? There is an option how you can debug it.

Switch RR to work over TCP:

workers:
    relay: "tcp://localhost:5000"

Use SocketRelay instead of SteamRelay:

$relay = new SocketRelay("localhost", 5000);

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

Weird, now it works. But I don't see anything being echo'd?

DEBU[0000] [rpc]: started
DEBU[0000] [http]: started
INFO[0002] 172.18.0.1 302 GET http://my-domain.eu.ngrok.io/
INFO[0004] 172.18.0.1 302 GET http://my-domain.eu.ngrok.io/
INFO[0009] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/_profiler/empty/search/results?limit=10
INFO[0013] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/_profiler/df487a
INFO[0017] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/cart/1
INFO[0022] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/cart/1
INFO[0023] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/cart/1
INFO[0025] 172.18.0.1 302 GET http://my-domain.eu.ngrok.io/_profiler/search?limit=10
INFO[0025] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/_profiler/d179e9/search/results?ip=&limit=10
INFO[0027] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/_profiler/d179e9
INFO[0030] 172.18.0.1 200 GET http://my-domain.eu.ngrok.io/_profiler/d179e9?panel=time

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Well, RR does not redirect STDOUT to the log, only STDERR. Does your worker die during the bootload? If so, try to run it manually php worker.php and see what it echoes and where.

If you can't find it (or don't want to) switch to TCP or Unix sockets (unix://socket.sock). It would work just a bit slower than pipes and will allow you to use STDOUT for your own purposes.

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

I started RR and in a new terminal opened php worker.php but it didn't output anything. It's just waiting... Also tried to move the SF kernel->boot to outside the while loop. No difference.

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

When doing a couple requests, and monitor rr http:workers it stays up. So the worker doesn't die.

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

So it's not bootloader issues, sounds like you output something to STDOUT while running your script. Is it possible you have some warnings and display_errors points to STDOUT?

Since it's working over sockets I can conclude that your workers are fine, but they definitely use pipes for something which creates conflicts with Goridge relays.

P.S. Warning: unpack(): Type C: not enough input, need 1, have 0 in /var/www/app/vendor/spiral/goridge/php-src/StreamRelay.php:110 this error is expected if you start your worker manually without properly formatting your data frames.

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

Do you use any header functions? They will write to STDOUT as well.

from roadrunner.

wolfy-j avatar wolfy-j commented on May 17, 2024

More info added here: https://github.com/spiral/roadrunner/wiki/PHP-Workers

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

I don't have any header functions in use. Also checked output of headers_list() and its empty. Is there a way of capturing the output of the php worker.php file?

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

I'm running this inside Docker btw, not sure if that's related.

from roadrunner.

ruudk avatar ruudk commented on May 17, 2024

Problem solved:

env(LOG_STREAM): 'php://stdout'

Sorry everybody!

from roadrunner.

dunglas avatar dunglas commented on May 17, 2024

Yes it is, some Symfony services are stateful. You must reset their states before handling a different requests to avoid side effects.

from roadrunner.

OO00O0O avatar OO00O0O commented on May 17, 2024

PM has a lot of reseting going on: https://github.com/php-pm/php-pm-httpkernel/blob/master/Bootstraps/Symfony.php

With reset tag in symfony now, this should be a lot smaller.

from roadrunner.

Related Issues (20)

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.