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

Set CGI environment variables by passing command line parameters to phpdesktop executable file #43

Closed
GoogleCodeExporter opened this issue Aug 25, 2015 · 11 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. run cmd.exe with this command (replace the name of your app..) : 
yourapp.exe --variable1=foo --variable2=bar

2. into the index.php inside the www folder, write : print_r($_SERVER)

3. Nothing is visible

What is the expected output? What do you see instead?
Try to read variables into the index.php by print_r($_SERVER).
Try to create a bridge between OS and PhpDesktop without deals with register

What version of the product are you using? On what operating system?
- php-desktop-msie_v10
- windows xp 64 (virtual machine)

Original issue reported on code.google.com by j...@ru5.fr on 8 Aug 2013 at 11:25

@GoogleCodeExporter
Copy link
Author

Related topic on the PHP Desktop Forum:

"Interaction between PhpDesktop and .exe (throwing param)"
https://groups.google.com/d/topic/phpdesktop/nNLWpjofqvY/discussion

Original comment by czarek.t...@gmail.com on 8 Aug 2013 at 11:49

  • Changed title: Set CGI environment variables through parameters passed to executable file
  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

[deleted comment]

1 similar comment
@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

It might take me about three weeks to find some spare time, but if no one is on 
this particular issue I can take it.

Original comment by ga...@approachfoundation.org on 13 Oct 2013 at 9:42

@GoogleCodeExporter
Copy link
Author

@approachfoundation.org : It might be a good solution if you can take it.
The solution we have choose is to write some parameters in the php.ini file.
But it's not the right way cause the process need to be re-start again when you 
want to use a variable.
So the problem is still alive

Original comment by josselin...@gmail.com on 14 Oct 2013 at 7:47

@GoogleCodeExporter
Copy link
Author

Referring to http://cesanta.com/docs.html#docs/Options.md I thought this should 
work out. I haven't test this yet aside from grabbing the arguments, as I still 
haven't had much time, but thought I'd post this anyway. If it works for 
anyone, you might want to use the concept but get the value of lpstrCmdLine 
into StartWebServer through another context instead of by passing, or maybe 
just use an overload. 

Basically I just turn WinMain's lpstrCmdLine into an array, similar to argv in 
standard main or wmain, and place them in the string format Mongoose prefers. 
Ideally, you can find a better function than explode to parse CLI arguments, 
this one will not allow spaces in options but should do OK.

This is just a quick run through but it could be used to work up a proper 
version pretty quickly.

-Garet


Line #230 main.cpp:
if (!StartWebServer(lpstrCmdLine)) {

Line #38 web_server.cpp
bool StartWebServer(&LPTSTR WinArgsCLI) {}


Lines #105-#116 web_server.cpp
    const char* options[] = {
        "document_root", wwwDirectory.c_str(),
        "listening_ports", listening_ports.c_str(),
        "index_files", indexFiles.c_str(),
        "cgi_interpreter", cgiInterpreter.c_str(),
        "cgi_pattern", cgiPattern.c_str(),
        "cgi_environment", WinToMongooseArgsCLI(WinArgsCLI),
        NULL
    };
    mg_callbacks callbacks = {0};
    callbacks.log_message = &log_message;
    callbacks.end_request = &end_request;
    g_mongooseContext = mg_start(&callbacks, NULL, options);

.
.
.




Added functions for web_server.php:

string WinToMongooseArgsCLI(LPTSTR lpstrCmdLine)
{
    string MongooseArgsCLI = "";
    vector<string> WinArgsCLI=explode( lpstrCmdLine," ");
    for(unsigned int i=1,L=WorkWith.size();i<L;i+=2 ){        Mongoose_CLI_KeyValueList = Mongoose_CLI_KeyValueList + WorkWith[i-1] +"="+ WorkWith[i] + ((i>=L-2)?"":",");    }

    return MongooseArgsCLI;
}

vector<string> explode (const string &str, const string &delimiter)
{
    vector<string> arr;

    int strleng = str.length();
    int delleng = delimiter.length();
    if (delleng==0)
        return arr;//no change

    int i=0;
    int k=0;
    while( i<strleng ){
        int j=0;
        while (i+j<strleng && j<delleng && str[i+j]==delimiter[j])
            j++;
        if (j==delleng){    //found delimiter
            arr.push_back(  str.substr(k, i-k) );
            i+=delleng;
            k=i;
        }
        else{
            i++;
        }
    }
    arr.push_back(  str.substr(k, i-k) );
    return arr;
}

Original comment by ga...@approachfoundation.org on 18 Oct 2013 at 6:30

@GoogleCodeExporter
Copy link
Author

I have successfully set the "cgi_environment" option in Mongoose to set the 
TMP, TEMP and TEMPDIR environment variables. See revision 89f4820f0bf1.

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 4:05

@GoogleCodeExporter
Copy link
Author

CGI environment variables can now be passed to the phpdesktop executables.

See revision 07c81718f5a5.

See the CGIEnvironmentFromArgs wiki page:
https://code.google.com/p/phpdesktop/wiki/CGIEnvironmentFromArgs

Original comment by czarek.t...@gmail.com on 22 Jan 2014 at 10:57

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Revision 8091beb8d108 fixes problems with port conflicts. A random port is now 
assigned when port is set to 0. The CGI environment variables did not work when 
both instances of application where listening on the same port. Now with random 
port support this issue is solved.

Original comment by czarek.t...@gmail.com on 25 Jan 2014 at 3:49

@GoogleCodeExporter
Copy link
Author

Chrome 31.4 and MSIE 1.12 released.

Original comment by czarek.t...@gmail.com on 26 Jan 2014 at 1:24

@GoogleCodeExporter
Copy link
Author

Project will move to Github. Find this issue at the new address (soon): 
https://github.com/cztomczak/phpdesktop/issues/43

Original comment by czarek.t...@gmail.com on 24 Aug 2015 at 3:20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant