2013年10月18日 星期五

在Windows PHP安裝ffmpeg-php


關於在Windows內使用ffmpeg-php, 網路上有很多方法, 
e.g. myownserver 在 How to install ffmpeg-php for Windows Apache HTTP Server 介紹安裝在xampp的方法, 從 http://sergey89.ru/files/ffmpeg-php/ 下載ffmpeg-php-5.3-win32-all.zip後, 逐步安裝後再用一支程式測試.
但是我是用AppServ + PHP 5.3.5 所以我用的方法

取得 ffmpeg-php
php.ini
首先解開之後, 先把 php_ffmpeg.dll 複製到 php5/ext內; php.ini 增加 一行 
extension=php_ffmpeg.dll

http.conf
我不喜歡複製到 System32 , 所以我在 http.conf 增加下列幾行:
#php 5.3
之前就有的
Loadfile "C:\AppServ\php5\php5ts.dll"
Loadfile "C:\AppServ\php5\libpq.dll"
 這次增加的
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avcodec-52.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avcore-0.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avdevice-52.dll"                                                 
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avfilter-1.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avformat-52.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\avutil-50.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\pthreadGC2.dll"
Loadfile "C:\AppServ\php5\ext\ffmpeg-php-5.3.1\swscale-0.dll"

phpinfo測試

測試ffmpeg.php
結果畫面

done.

PHP在Windows環境下執行

名詞解釋

首先說明VC6及VC9:

VC6 : 就是使用 Visual Studio 6 compiler 這個編譯器編譯的.
VC9 : 就是用微軟的 Visual Studio 2008 compiler 編譯的.
TS : Thread Safe 線程安全, 執行時會進行線程(Thread)安全檢查, 以防止有新要求就啟動新線程的CGI執行方式而耗盡系統資源
NTS : Non Thread Safe 非線程安全, 在執行時不進行線程(Thread)安全檢查
ISAPI(Internet Server Application Programming Interface)執行方式是以DLL動態庫的形式使用, 可以在被用戶請求後執行, 在處理完一個用戶請求後不會馬上消失, 所以需要進行線程安全檢查, 這樣來提高程序的執行效率.
FastCGI : 執行方式是以單一線程來執行操作, 所以不需要進行線程的安全檢查, 除去線程安全檢查的防護反而可以提高執行效率.

 

PHP 官網說明:

Which version do I choose?

If you are using PHP with Apache 1 or Apache2 from apache.org you need to use the VC6 versions of PHP
If you are using PHP with IIS you should use the VC9 versions of PHP
VC6 Versions are compiled with the legacy Visual Studio 6 compiler
VC9
Versions are compiled with the Visual Studio 2008 compiler and have improvements in performance and stability. The VC9 versions require you to have the Microsoft 2008 C++ Runtime (x86) or the Microsoft 2008 C++ Runtime (x64) installed

Do NOT use VC9 version with apache.org binaries
 

Thread Safe線程安全

Linux 使用多進程(process)不同於Windows採用的多線程(Thread)的工作模式; 而CGI是以Linux的多進程所設計的, 所以如果在IIS 的 PHP 使用 CGI 模式, 每次HTTP的請求PHP都需重新加載及缷載, 所以速度慢。
IIS另外一個選擇是使用ISAPI的方式(早期的ASP.NET也是用這種方式), 因為php5nsapi.dll是用多線程設計的(Thread safe),符合Windows多線程的設計,速度較快。
但是在選擇PHP Extension時就要注意, 必須使用TS(Thread safe)的版本, 否則會搞垮IIS. 但是大部份的PHP_Extension都是針對Linux的多進程設計的.
為了在Windows IIS兼顧速度及線程安全, 微軟推出FastCGI; FastCGI保留了CGI的工作模式, 又提供一個pool機制管理重覆使用的進程, 確保non-thread-safe的libraries可以正常執行。
 

結論

使用ISAPI方式, php extension 就要用Thread Safe的版本; 如果使用FastCGI就不用Thread Safe(non-thread-safe)了,效能還更好呢.
 
 

2013年9月26日 星期四

用Maven執行Java程式

Eclipse 用習慣了,IDE提供方便的操作,也讓我變笨了.

在命令列使用maven要執行JAVA console 程式,有一個好用的plug-in :  exec-maven-plugin

 

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
</configuration>
</plugin>
 
使用mvn exec:java 命令就可以執行了
mvn-exec-java

 


提示1


如果你跟我一樣對 pom.xml的schema不熟,不知道plugin要放在哪裡, 這裡有完整的結構.

<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
 

提示2


如果程式需要加*參數*

<project>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.clickap.test.NeoSpring</mainClass>
<arguments>
<argument>argument1</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
 
 

2013年9月24日 星期二

影像處理的日子

這張圖很熟悉吼~

lenna

本尊出現在 IS&T 50週年慶

無意中找到這篇在交大的網站上  http://www.csie.nctu.edu.tw/~zlxuan/lena/lenna.html 

是不是勾起了很多回憶 Smile

2013年9月13日 星期五

Maven專案在Eclipse Run on Server

想在Eclipse 操作Maven 2 專案, 現在有比較方便的外掛  :  M2E – WTP
內置圖片 4
M2E-WTP
目前是 1.0.0版 http://wiki.eclipse.org/M2E-WTP/New_and_Noteworthy/1.0.0

0.安裝方法
我直接用 Install New Software方式安裝 網址 : http://www.eclipse.org/m2e-wtp/download/
勾選 m2e 及 m2e-wtp 兩項.
因為我的Helios已經安裝M2E 1.4版了, 所以只要選取 m2e-wtp 這項即可.

1.安裝後, 新增Maven專案


2.在Filter用關鍵字 webapp
選取org.apache.maven.archetypes

3.給命名空間(Group Id)及專案名稱(Artifact Id)


神奇的事發生了, 在專案名稱按右鍵,選取Run on Server
你已經設定好的Tomcat
執行結果

太好了, 以後可以用熟悉的方式 Eclipse 在  Maven 的 Web專案用  Run on Server 了.

要注意的是 M2E-WTP 跟 m2eclipse-wtp 不能同時安裝.

參考自http://www.eclipse.org/m2e-wtp/download/

2013年9月3日 星期二

硬碟空間不夠?

當然清除回收桶, 新增移除程式一定有幫助的.
CCleaner , Sweep 之類的軟體也不錯(google就找到一堆了)
我要介紹的是 SpaceSniffer 如圖


SpaceSniffer
啟動後等一下, 它後幫你把各個資料夾所佔的空間圖形化, 是不是一目了然?
這裡可以下載

分享我的經驗(Windows7)
ProgramData\Microsoft\Search\Data 高達12G, 使用控制台->索引->進階 按下重新索引(Rebuild)後剩下84MB.
ProgramData\Microsoft\OEMOffice14 直接砍掉
ProgramData\Microsoft\HelpLibrary 直接砍掉, 但是在 C:\Program Files\Microsoft Help Viewer\v1.0\HelpLibManager.exe.config 加上一行 <add key="FirstTimeRun" value="True" /> , 下次執行時再詢問.

Java檢查記憶體使用情形

主要是因為出現了 java.lang.OutOfMemoryError: Java heap space

 

JDK6以後附了 Java VisualVM (jvisualvm.exe) 在bin的目錄內, 這裡有詳細說明;

1.Overview

先把你要檢查的Java執行起來, 然後打開jvisualvm(如圖), 在左邊Applications內點選你的JVM(我是用OC4J), 就可以在Overview看到JVM的運作環境及設定的參數.

 

jVisualVm

因為要測heap , 你會發現上圖我有加了一些參數, 這裡說明一下:

-XX:+HeapDumpOnOutOfMemoryError   在出現 OutOfMemoryError 時會產生一個 hprof的檔案(e.g. java_pidxxxxx.hprof, 預設會寫在JVM所在路徑, 也可以加 -XX:HeapDumpPath=yourpath ), 方便我們檢查記憶體使用的情況; 使用方法請看這裡 .

hprof 檔可以用 Eclipse memory analyzer (mat, http://www.eclipse.org/mat/ ) 打開來看, 建議載 Stand-alone Eclipse RCP Applications 的版本比較方便(如圖)

mat-1

-Xms512m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=256m  這幾個參數相信大家都很熟悉, 我就不多說了; 只是 Permanent Size 本來大家都說很小(只要64m), 可是經過 jVisualVM測過, 我發現我的 AP 一下就超過了, 所以我把它改為 128m 起跳; heap size 也把它加到 512m.

 

 

2.切換到Monitor還有圖(chart)

jVisualVm chart

 

接下來就是觀察記憶體使用情形, 然後跟著調整及修正了.

參考自 http://javarevisited.blogspot.sg/2011/09/javalangoutofmemoryerror-permgen-space.html