|
|
PHP Linuxで実行するTable IndexPHP+LinuxでAir(Action Script 3.0)を実行する環境を構築する インストールFlex SDK をインストール Adobe AIR SDK をインストール ↑設置場所はどこでも良い Air作成ファイルhello.as
package
{
import flash.desktop.NativeApplication;
import flash.display.Sprite;
import flash.events.InvokeEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import mx.utils.ObjectUtil;
public class hello extends Sprite
{
public function hello()
{
super();
//外部から渡された引数を取得する
NativeApplication.nativeApplication.addEventListener(InvokeEvent.INVOKE , this._onInvoleEvent);
}
private function _onInvoleEvent(evn:InvokeEvent):void
{
trace("current_dir = " + evn.currentDirectory.url);
trace(ObjectUtil.toString(evn.arguments));
var path:String = evn.currentDirectory.url + "/" + evn.arguments[0];
//ファイルを出力する
var file:File = new File(path);
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("test");
stream.close();
//アプリケーションを終了
NativeApplication.nativeApplication.exit();
}
}
}
hello-app.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://ns.adobe.com/air/application/1.5">
<id>HelloASCommandLineTool</id>
<filename>hello</filename>
<name>hello</name>
<version>v1</version>
<initialWindow>
<content>hello.swf</content>
</initialWindow>
</application>
コンパイルしてhello.swfを出力する amxmlc -output hello.swf hello.as PHPユーザーの権限の変更apacheユーザーをsudo権限を持たせる visudo www-data ALL=(ALL) ALL スクリプトファイルの作成PHPからrootでシェルスクリプトを実行する <?php $command = "echo 'password' | sudo -u root -S /home/user/sh/adl1.sh"; shell_exec($command); ?> シェルスクリプト1 Xウインドウを立ち上げているユーザーに変更してから次のシェルを実行する #!/bin/sh su usr -c "/home/user/sh/adl2.sh" シェルスクリプト2 flex SDKパスを設定&ディスプレイデバイスを設定 #!/bin/sh export PATH=$PATH:/usr/local/flex3/bin:/usr/local/flex3/player/debug; export DISPLAY=unix:0; adl /home/user/sh/hello-app.xml -- arg1 arg2 完了あとは http から PHP にアクセスしてAirが実行される事を確認してください。 |