Posts tonen met het label Quercus. Alle posts tonen
Posts tonen met het label Quercus. Alle posts tonen

25 mei 2009

Using PHP on GAE


Google is now supporting 2 languages for Google App Engine: Phyton and Java. This article shows how you can use PHP on Google App Engine.

Running PHP on GAE is possible by using Quercus from Caucho, Quercus implements PHP in Java, see below URL's about running Quercus on GAE>
Assuming you have a Google App Engine website running with Java enabled and also localy installed the GAE Java SDK and the Google Eclipse plugin.

Assuming also that you did the Java Getting Started tutorial to get hands-on experience with the GAE Java SDK and the Google Eclipse Plugin.

Then you can also get PHP running on GAE with below steps.

1) Create a Google Web Application inside Eclipse

Optional: De-select GWT on the "New Web Application project" wizzard.

2) Copy resin.jar from Resin 4.0 to WEB-INF/lib

Add resin.jar to the java build path: Right-click on the project-name, select 'properties' then 'Java build path' and the add resin.jar under 'Libraries'

3) Modify war/WEB-INF/web.xml so that it contains (also) below content
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>quercus</servlet-name>
<servlet-class>com.caucho.quercus.servlet.GoogleQuercusServlet<servlet-class>
</servlet>

<servlet-mapping>
<url-pattern>*.php</url-pattern>
<servlet-name>quercus</servlet-name>
</servlet-mapping>
4) Add below lines to war/WEB-INF/appengine-web.xml
<static-files>
<exclude path="/**.php" />
</static-files>

<resource-files>
<include path="/**.php" />
</resource-files>
5) Create the war/index.php file.
<?php 

phpinfo();

?>
6) Run the development server.

7) Surf to: http://localhost:8080/

..... Read more .....

Using the GAE log with PHP


With a very small java source you can use the GAE log with PHP. You can see this log on the console tab in Eclipse, or with the GAE Dashboard. It is also possible to download the logs from GAE with the appcfg.sh script.

This article shows you how you can use this log in your PHP scripts running on Google App Engine.

The usage in your PHP scripts is:
logInfo("I just want to say Hello!");
logWarning("Not good, xxx is not supported");
logSevere("Big big troubles");
First add resin.jar to the build path for your GAE project in Eclipse with properties -> Java build path -> Libraries

Below the Java code, save it as src/gae/php_log.java in your GAE project in Eclipse.
package gae;

import java.util.logging.Logger;
import com.caucho.quercus.module.AbstractQuercusModule;

public class php_log extends AbstractQuercusModule {

private static final Logger log = Logger.getLogger(php_log.class.getName());

public void logInfo(String message) { log.info(message); }
public void logWarning(String message) { log.warning(message); }
public void logSevere(String message) { log.severe(message); }

}
To make Quercus aware of your new log fuctions, add below line to the file src/META-INF/services/com.caucho.quercus.QuercusModule (create this file if it not yet exists)
 gae.php_log
To activate the INFO severity (default it is at WARNING severity), add below line to the war/WEB-INF/logging.properties file.
 gae.php_log.level=INFO
See quercus: java and php integration for more information how to write your own PHP functions with Java for Quercus PHP on GAE.
..... Read more .....

Sending email with PHP at GAE

Currently sending email from PHP scripts on Google App Engine is not working. Most likely this will be possible in the future again when the nice folks of Caucho adjust Quercus to the GAE sandbox.

This article shows how to use a small Java program for sending email from PHP at Google App Engine.

With using a small java source you can send email from your PHP scripts at GAE with below line:
 gaeMail('me@gmail,com', 'someone@inter.net', 'Subject', 'Hi, how are you?');
First add resin.jar to the build path for your GAE project in Eclipse with properties -> Java build path -> Libraries

Below the Java code, save it as src/gae/email.java in your GAE project in Eclipse.
package gae;

import java.util.Properties;

import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import com.caucho.quercus.module.AbstractQuercusModule;

public class email extends AbstractQuercusModule {

public void gaeMail(String from, String to, String subject, String body)

throws java.io.IOException {

Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);

try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(body);
Transport.send(msg);
} catch (AddressException e) {
// ...
} catch (MessagingException e) {
// ...
}

}

}
To make Quercus aware of your new email fuction, add below line to the file src/META-INF/services/com.caucho.quercus.QuercusModule (create this file if it not yet exists)
 gae.email
See quercus: java and php integration for more information how to write your own PHP functions with Java for Quercus PHP on GAE.
..... Read more .....

24 mei 2009

SQL to JDO for PHP at GAE


Started a project that makes it possible to use 'normal' SQL like below in PHP scripts at Google App Engine.
sql("insert into demo (field1, field2) values(1, 'Yes it works')");

$rows = sql("select demo, field1, field2 from table order by demo desc");

sql("update demo set field1 = $field1 where demo = $demo");

sql("delete from demo where demo = $demo");

There is now a new version, see below blog postings about it.

pQg- Use SQL in PHP scripts at GAE

How to use pQg
..... Read more .....