donnikitos / vite-plugin-php

Vite's speed and tooling to preprocess PHP-files!
https://www.npmjs.com/package/vite-plugin-php
MIT License
34 stars 0 forks source link

POST-Requests never finish #29

Closed krei-se closed 1 month ago

krei-se commented 1 month ago

Hey, it's me again ;D

I work around this by using method=GET for my forms for now, but i spent 1 day debugging this, took a look into router.php (noice internal parameter array key!!) and even made sure i don't include a page with the same name as an included file (had login.php for both the page and the check).

Soooo i guess _POST request just don't work in dev, it's totally fine on apache2.

Steps to reproduce:

<?php
print_r($_POST);
?>

<form action="?" method="POST"> <!-- yes you can omit action, action="test.php" same error -->
<input type="text" name="test" value="test"/>
<input type="submit" name="submit" value="submit"/>
</form>

never loads the page. Restarted the server, etc. - nothing. method="GET" works ootb

donnikitos commented 1 month ago

Interesting issue! Will definitely look into that ASAP; I am glad someone is using my plugin almost as active or even more then me :D

krei-se commented 1 month ago

It's a total breeze developing with this, i have best security with server backend and can handle xml to typescript now fine.

https://www.techempower.com/benchmarks/ still has nginx-php-mysql/postgresql at 300.000 of 600.000 best (rust/c) so more people should use this, you can get interpreter languages, best security and speed at 50% c-level. If you take a look at frameworks like laravel or rubyonrails your plugin is like 100 times faster.

top 1 post yesterday on hackernews: https://news.ycombinator.com/item?id=41469040

Maybe do a show HN there when most bugs are gone?

donnikitos commented 1 month ago

So, this critical bug is fixed now!

Yeah, PHP still rules, hence the plugin ;) A bigger announcement especially on HN would definitely be beneficial! And I think the plugin is now getting almost to the point of being pretty stable and usable for development 💪🏼

krei-se commented 1 month ago

What news to wake up to :D I updated and it works like a charm! I tried to make sense of the middleware as $_FILES is still empty, but it looks like a lot of bending vite to make it work and i was mostly interested in not having to workaround between deployments, can use method=POST in both and don't need to clean the URL by script.

I should, and most coders will, implement TS for uploads anyway.

There are sometimes missing the correct source file in errors, as everything is fed through the router, but this mostly an issue in bigger refactorings when it's not clear where one missed to fix a variable name, etc.

Warning: Undefined variable $nonexistant in /krei.se/node_modules/vite-plugin-php/dist/router.php(37) : eval()'d code on line 286

I think this will be known to other developers that this is not a fault of the plugin, but i modified router.php to catch warnings as errors and print out a more detailed stack trace with the correct sourceFile:

(function () {

        set_error_handler(function ($errno, $errstr, $errfile, $errline) {
                // Throw an ErrorException so it can be caught by the try-catch block
                throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
        });

    try {
        eval('?> ' . func_get_arg(0) . ' <?php');
        die();
    } catch (\Throwable $th) {
        die(
                        "Error: " . $th->getMessage() . "<br>" .
                        "In file: " . func_get_arg(1) . "<br>" .
                        "On line: " . $th->getLine() . "<br>" .
                        "Stack trace: <pre>" . $th->getTraceAsString() . "</pre>"
                );
    }
})($source, $sourceFile);

For me this is fine, but "legacy" php-projects will throw a lot of warnings that usually gets ignored by paid for time programmers lol. Edit: Just found how to treat warnings as errors in php.ini - forget about this.

All in all i would say this plugin is quite ready to be used - the most important aspect for me is the ease of file copying to the compiled app without the need for vite-static-copy, etc.

I will continue working on my project, if you ever start to like it, feel free to list it as a reference and thanks for the instant resolution of those annoyances!