その他

PHP on GAE (Google App Engine) を試してみました

こんにちは、中川です。

今回は、ちょっとsymfonyからは離れてGoogle App Engine (以下GAE)上でのPHPを試してみました。

社内の別のメンバーがHelloWorldまでは試していたり、いろいろな記事等で動くというのは知っていたのですが、
どの程度既存のコードが使えるものかといじってみました。

「PHP on GAE」の環境については、「PHPも使える! Google App Engine for Java(前編)|CodeZine ( http://codezine.jp/article/detail/3948 ) 」のままで
すんなり動作するところまで30分程度でいけました。

で、ちょっと試してみたのですが、なかなかこれが、、、

まずは、phpinfo 。
http://asialphptest.appspot.com/info.php


<?php
phpinfo();
?>

次に、使える関数、エクステンション。
http://asialphptest.appspot.com/functions.php


<h2>extensions</h2>
<pre><?php print_r(get_loaded_extensions()); ?></pre>
<h2>functions</h2>
<pre>
<?php
$funcs = get_defined_functions();
sort($funcs['internal']);
print_r($funcs['internal']);
?>
</pre>

次は外部コンテンツの取得。(不完全)
http://asialphptest.appspot.com/urlfetch.php


<?php
/**
 * PHP on GAE 外部コンテンツ取得(未完成)
 */
function file_fetch_contents($urlString) {
import java.net.URL;
import java.io.InputStreamReader;
import java.io.BufferedReader;
$url = new URL($urlString);
$reader = new BufferedReader(new InputStreamReader($url->openStream()));
$result = '';
while (($line = $reader->readLine()) != null) {
$result .= $line;
}
$reader->close();
return $result;
}
$url = "http://google.co.jp/";
$url = "http://api.pathtraq.com/pages?api=json &url=" . $url;
$contents = file_fetch_contents($url);
//短いコンテンツなら取得できているようだが、2行目以降がとれなーい\(^o^)/
echo $contents;
?>

最後にメール送信。(エラー)
http://asialphptest.appspot.com/mail.php


<pre>
<?php
/**
 * PHP on GAE メール送信テスト(失敗)
 */
/**
 * mb_send_mailは送れなかった\(^o^)/
 */
mb_send_mail("yoshiki@example.co.jp", "subject", "message");
/**
 * Java呼び出しでやってみるも途中でエラー\(^o^)/
 */
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.Session;
import java.util.Properties;
$address = new InternetAddress("yoshiki@example.co.jp");
$props = new Properties();
$session = Session::getDefaultInstance($props, null);
$message = new MimeMessage($session);
$message->setFrom($address);
$message->setSubject("testtest", "ISO-2022-JP");
$message->setText("asdfsdfsd");
//ここでエラー Message.RecipientType.TO? $addressが問題?
$message->addRecipient('To', $address); 
Transport::send($message);
?>
</pre>

他にもいろいろ試したかったのですが、今日はこのあたりまでであきらめました。
結果的には調査不足のまま終わってしまいましたので、引き続き何かと試してみたいと思います。

「もっといいやり方があるよー」「ここがおかしいよー」などありましたらお手数ですが是非お教えくださいm(_ _)m

author img for asial

asial

前の記事へ

次の記事へ

一覧へ戻る
PAGE TOP