thttpd and php in CGI mode - php

Is there a way to make PHP and thttpd work together in CGI mode? There are some pieces of information here and there but our naive attempts failed so far as it seems like PHP doesn't understand the environment variables set by thttpd and therefore fails to find the script file.
Building php as thttpd module is not desirable due to custom build configuration (it's an embedded device) - but possible as a last resort. However, I'd like to avoid that using CGI approach if possible.

Wrap
/cgi-bin/php.cgi:
#!/bin/sh
export DOCUMENT_ROOT=/home/alex/thttpd/www
export SCRIPT_NAME=/cgi-bin/test.php
export SCRIPT_FILENAME=/home/alex/thttpd/www/cgi-bin/test.php
exec /usr/bin/php-cgi
or patch thttpd to export a suitable env for php-cgi

This may not be the answer you're hoping for, but there seem to be no development in thttpd. I'd recommend mongoose. MIT-licence, good for embedded and easy php setup,
Runs on windows as well.
php setup: go WindowsUsage and scroll down.
UPDATE: new link
http://cesanta.com/docs/PhpWebsite.shtml

Related

run python script from phpstorm

I have a php project I'm working on using PhpStorm. I have a python script which manipulates my css file in a certain way before uploading it to the server (it's irrelevant to the question, but if you're curious, mostly related to language support).
I'd love to be able to run it directly from phpstorm, but I'm unsure how to do it (I'm guessing it's possible but I couldn't find any reference to something of the sort, and I'm kinda new to this IDE). I know I can rewrite the script with php but I'd rather not (I'm still a pythonist at heart).
Anyone had to tackle something of the sort?
Thanks in advance!
p.s. I'm running Ubuntu if that matters.
Use File Watcher plugin for that (should be bundled since v7 by default) -- this way such script will be run on each of desired modified files on save automatically.
http://confluence.jetbrains.com/display/PhpStorm/File+Watchers+in+PhpStorm
Alternatively you can use External Tools functionality and invoke it manually when desired.
http://www.jetbrains.com/phpstorm/webhelp/external-tools.html
According to the help page you can run scripts in the "Before launch". IMHO you can configure an external tool to be your python script (change +x to make it executable...).
Alternatively, I think you could install the python plugin (I've never tried it).

Executing ANT from PHP

I have an HTML form which I am submitting to a PHP script. I am using PHP to write an XML file based on the form input, and then I would like to have PHP execute an ANT buildfile that will use the XML as input for an XSLT task. All of this is part of a much larger application, none of which is exposed beyond our LAN, so security is not a huge concern of mine. My problem is that I cannot get the PHP exec task to start ANT. I have tried seemingly every combination of executing a BAT that calls ANT, using the full path to the ANT binary, calling ANT with java, etc. All roads lead to:
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
I am running PHP 5.3 on Windows Server 2008 running IIS7. The PHP is located in inetpub/wwwroot/etc. Ant is installed in C:\Program Files. I personally don't believe it's a permissions issue, but I could be wrong. I have scoured the web in search of the answer, but I have only found the question unanswered or suggestions similar to those mentioned below.
I am currently attempting to install phing, and will consider another server-side scripting language to accomplish the same job (I am just way more comfortable in PHP). But if anyone knows of the issue and how I can work around it that would be awesome.
Cheers!

Writing a CLI for a php-based CMS (Similar to Drush)

I've been working on a CMS for a few years and I actually implemented a jquery-based console in the admin area, where you could do some handy things like enable/disable modules and so on.
I recently fiddled around with drupal and decided to install cygwin along with drush.
I tried googling around but figured this might be an unusual question: How does one go about creating a CLI for a php-based CMS? And exactly how does exactly drush worK? I mean, I know that it runs from the command line as a batch script in windows. But how does it interact with PHP and so on?
I do know some basic C# but this shouldn't be very hard once i figure out how this fits together. (php, sql, etc).
Any help is appreciated, thanks in advance :)
You can run a php cli from the terminal only when you have php compiled with cli support. Additional you need to specify an interpreter and pass the path to the script as argument. But you can also use a shebang #!/path/to/php. A better practise would be to use the env variable and not hardcode the path to php: #!/usr/bin/env php. Read here about it: http://tech.vg.no/2012/02/21/dont-hardcode-php-executable-path-in-shebang/.
Basically you can write a simple CLI shell with a infinite loop plus a 'exec()' or 'shell_exec()' PHP functions. you should get the user commands and send it to shell_exec() function for execute in a system shell and return the output of that to the user.
i.e:
while(TRUE){
if($input != 'exit')
$output=shell_exec($input);
else
break;
echo $output;
}
you can add other options and customize this simple loop.
you can call external programs with 'exec()' function.

Is it possible to launch a php script at apache startup?

As the title says, I want to know if it is be possible to automatically launch a PHP script when a restart of apache is done.
MORE INFO EDIT:
I will try to explain what is the purpose of this, the best I can. We are currently refactoring our application and we'll be stuck with 2 differents configuration file system for the time being, until all of the application flows are refactored (might take more than a year). The old one is using simple flat file in the key=value format (i.e. www.conf), while the new system will use cacheable php files (i.e. www.php). We need to replicate to www.php any config changes made in www.conf.
Since Apache gets restarted whenever there is a config change in www.conf, I thought it might be a good workaround solution to launch a PHP script, that would replicate the www.conf to www.php.
You need to modify you startup script for your apache.
Open your startup script, it should be in /etc/init.d/apache or apache2
Search for the start / restart section and add your cli call for your PHP script.
Example:
restart)
[..]
php -q /tmp/myscript.php &
;;
Where /tmp/myscript.php is your php script that you want to launch.
The "&" at the end will start the script in the background so your startup will not wait until your php script has ended. If you want to wait until it has ended, remove the &.
You should not put such thing into your startup scripts, there might be better solutions. What are trying to achieve?
At the risk of offending people (like myself) who prefer neat clean solutions, is changing the Apache's default start script an option for you? If so, that'd be the simplest solution

Can you use scons to build PHP extensions?

The standard way of writing PHP extensions is to use autoconf/automake alongside a script called phpize, which seems to generate your autoconf configuration based on a template that's specific to your PHP environment. This let's it build the PHP extension for the right version of PHP, etc.
autoconf and the m4 language that is used to configure it is arcane, and people have written alternatives, such as scons. I want to be able to use one of these when building a PHP extension.
In principle, you should be able to use scons or similar tools to build PHP extensions. However, I can't see how you would replace the phpize step.
Has anyone had any success in building PHP extensions with scons, or another more modern build tool?
The path of least resistance would be to have SCons run autoconf, phpize and whatever else is needed for your PHP extension. You may be able to extract the compiler configuration out of there and let SCons do the actual building, or you can simply have SCons run "make".
Declaring shell command targets from SCons is easy, but getting dependencies right is always tricky.
Basically you will have to let SCons know of any intermediate file produced by these external tools. This way it can not only properly clean them, but it can also cache the whole series of steps based on the content signature of each intermediate result (MD5 checksum).
Proper caching will significantly reduce the number of times these external tools will actually need to be invoked as the code base changes.
While I don't think somebody has written a specific solution for PHP, there are lots of custom builders on the SCons wiki that do similar things.
phpize(1) is just a shell script, so i guess you could modify it to work with scons...

Categories