Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi tenancy in worker mode #219

Closed
DubbleClick opened this issue Sep 21, 2023 · 14 comments
Closed

Multi tenancy in worker mode #219

DubbleClick opened this issue Sep 21, 2023 · 14 comments

Comments

@DubbleClick
Copy link
Contributor

In the documentation it's specified that you can pass env variables to the worker. Is it also possible to spawn workers per-vhost? E.g.

frankenphp {
        # num_threads 4
        worker {
            file /var/www/app/public/index.php
            num {{ half num of cpu cores }}
            env APP_ENV {{ depends-on-the-host }}
        }
    }

staging.example.com {
    route {
        php {
            root /var/www/app/public
            env APP_ENV staging
        }
    }
}

prod.example.com {
    route {
        php {
            root /var/www/app/public
            env APP_ENV prod
        }
    }
}

Or even spawn two entirely different workers?

app.example.com {
    route {
        php {
            root /var/www/app/public
            # spawn worker for this?
        }
    }
}

otherapp.example.com {
    route {
        php {
            root /var/www/otherapp/public
            # spawn different workers for this?
        }
    }
}
@francislavoie
Copy link
Contributor

One way to do this would be to have "named workers" so you can have more than one worker configured in global options, then refer to a specific one in the site block.

@DubbleClick
Copy link
Contributor Author

One way to do this would be to have "named workers" so you can have more than one worker configured in global options, then refer to a specific one in the site block.

Thank you for the answer, the documentation doesn't seem to mention named workers, though.

I can't seem to find it in the source either, looking at

type workerConfig struct {
// FileName sets the path to the worker script.
FileName string `json:"file_name,omitempty"`
// Num sets the number of workers to start.
Num int `json:"num,omitempty"`
// Env sets an extra environment variable to the given value. Can be specified more than once for multiple environment variables.
Env map[string]string `json:"env,omitempty"`
}

So I take it this has to be implemented first?

@dunglas
Copy link
Owner

dunglas commented Sep 28, 2023

Multi-workers is already supported, but not @francislavoie proposal. It would be nice to add it!

@DubbleClick
Copy link
Contributor Author

Okay, I'll see if I can implement it when I'm done with ext-imap and ext-ldap in spc. The option to run multiple sites is crucial - luckily it's possible without workers for now so the switch will be easy later.

@dunglas
Copy link
Owner

dunglas commented Sep 28, 2023

This hack should also do the trick (as a workaround):

{
    frankenphp {
        worker /var/www/staging/public/index.php
        worker /var/www/prod/public/index.php
    }
}

staging.example.com {
    root /var/www/staging/public/
    // ...
}

prod.example.com {
    root /var/www/prod/public/
    // ...
}

And if you need to share some files between prod and staging, use symlinks. WDYT?

@DubbleClick
Copy link
Contributor Author

DubbleClick commented Sep 28, 2023

Oh that's smart, thank you. Will definitely add it to the documentation later.

I've got php-imap and php-ldap to compile now so they should be ready for the static binaries soon, but I'm not sure what the best place is to enquire whether php-imap is thread safe or not. The GitHub repository or a mailing list?

Edit: It's not thread safe and will be dropped from php.

@terefang
Copy link

terefang commented Nov 7, 2023

is there a timeframe for ldap ?

@DubbleClick
Copy link
Contributor Author

It's already merged.

@francislavoie
Copy link
Contributor

For reference: #203

@terefang
Copy link

so it will be in the next rc and/or in 1.0 final ?

@DubbleClick
Copy link
Contributor Author

DubbleClick commented Nov 11, 2023

it's already in the current rc...?

are you not using the static version, but the docker version perhaps? you need to check the documentation how to install ldap then. It's just one extra line

@terefang
Copy link

i am using the 1.0.0.rc2 static musl version from the release page.

the phpinfo() page does not show a ldap section

@DubbleClick
Copy link
Contributor Author

v1.0.0-rc.2...main

You're right, it's not in current RC yet. Sorry for the confusion.

You can fork this repo and manually build it with docker, or trigger a workflow. I'd upload you a binary, but I'm not sure if that's discouraged here since authenticity couldn't be verified.

@terefang
Copy link

no problem, i can wait to official release

@dunglas dunglas closed this as completed Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants