顯示具有 php 標籤的文章。 顯示所有文章
顯示具有 php 標籤的文章。 顯示所有文章

星期三, 1月 15, 2025

移除 .user.ini 失敗,該如何解決

在設定php專案時會產生 .user.ini 無法移除

1. 使用lsattr查詢屬性

lsattr .user.ini

----i-------- .user.ini

如果出現 i 屬性,表示該文件已被標記為「不可修改」或「不可刪除」。


2. 先移除此屬性後即可刪除

sudo chattr -i .user.ini

sudo rm -rf .user.ini

星期日, 5月 21, 2017

[Lavarel] 使用View::exists 判斷view blade是否存在

記錄一下為了做樣版切換機制需要用到的View:exists方法 http://stackoverflow.com/questions/32102272/how-to-include-a-blade-template-only-if-it-exists You can use View::exists() to check if a view exists or not. @if(View::exists('path.to.view')) @include('path.to.view') @endif Or you can extend blade and add new directive Blade::directive('includeIfExists', function($view) { });

星期一, 10月 03, 2016

[php] Fatal error: Maximum execution time of 30 seconds exceeded 超過最長執行時間錯誤

今天寫批次計算演算法時,
發生了此錯誤 Fatal error: Maximum execution time of 30 seconds exceeded
因為預設php是30秒,所以爆開了。
可以簡單為單一執行的程式加入set_time_limit

set_time_limit(0) //則是無上限

沒事不要設定全域的執行時間:D ,想不開可以在php.ini檔設定。
可以找到max_execution_time的設定屬性

星期一, 7月 25, 2016

[MAMP] 手動變更php版本

如果想要自行變動php版本的話,可以下載php版本後
放置以下目錄


再修正httpd.conf

sudo vim /Applications/MAMP/conf/apache/httpd.conf


開啟後再修正版本模組即可

#LoadModule php5_module        /Applications/MAMP/bin/php/php5.6.10/modules/libphp5.so

#你想要的版本
LoadModule php5_module        /Applications/MAMP/bin/php/php5.6.24/modules/libphp5.so

[MAMP] Mac的php版本改用MAMP的php版本的方法

直接用MAMP來取代mac原本裝裝php5版本,

請參考下面流程,請注意MAMP_PHP改為你要使用的版本號即可

open terminal, type
touch ~/.bash_profile; open ~/.bash_profile
edit as follows below, save, quite and restart terminal or alternately
source ~/.bash_profile
to execute new PATH without restarting terminal
and in the fashion of the DavidYell's post above, also add the following. You can stack various variables by exporting them followed by a single PATH export which I demonstrated below
export MAMP_PHP=/Applications/MAMP/bin/php/php5.6.10/bin
export MAMP_BINS=/Applications/MAMP/Library/bin
export USERBINS=~/bins
export PATH="$USERBINS:$MAMP_PHP:$MAMP_BINS:$PATH"
http://stackoverflow.com/questions/4145667/how-to-override-the-path-of-php-to-use-the-mamp-path

星期四, 6月 23, 2016

[php] 用命令提示字元檢查語法是否有誤

今天寫物件發生一些sytax錯誤,
開了display_errors, error_reporting都沒什麼錯誤印出來。
於是直接使用cmd line語法檢查..

php -l UserScoreGradeDAO.class.php 
No syntax errors detected in UserScoreGradeDAO.class.php

就會告訴你錯在哪一行了,真的方便多了。

星期二, 5月 24, 2016

[PHP] php-extension: 範例練習

經過前幾次的練習與說明,筆記一下因為自已的需求測試的範例


範例: 從自已建一個額外的C語言的檔案呼叫



1.修正一下config.m4指定載入額外的C語言

dnl config.m4 for extension


PHP_ARG_ENABLE(foo, whether to enable foo extension support,
  [--enable-foo Enable foo extension support])

dnl 檢測extension是否已被啟動
if test $PHP_FOO != "no"; then

 AC_MSG_CHECKING("start to enable extension");

  dnl PHP_NEW_EXTENSION(foo, php_foo.c, $ext_shared)

  dnl 注意多引用了自定義C語言func
    PHP_NEW_EXTENSION(foo, php_foo.c hello_world_c.c, $ext_shared)


fi


2.先建立自已的C的實作與標頭檔
hello_world_c.h, hello_world_c.c

int hello_world_c_add(int, int);


/*Hello World program*/

#include <stdio.h>
#include "hello_world_c.h"

int hello_world_c_add(int a,int b){
 int sum = 0;
 printf("hello_world_c_add is coming Orz\n");
 printf("%d\n", a);
 printf("%d\n", b);
 sum = a+b;
 printf("sum=%d\n", sum);

 return sum;
}
int main(){
 printf("Hello World C :D");
 printf("sum=%d",hello_world_c_add(10,10));
 return 0;
}


3. 在php_foo.c裡面include hello_world_c.h檔


#include "hello_world_c.h"//內部的c func

#include "php_foo.h"

#if COMPILE_DL_FOO
ZEND_GET_MODULE(foo)
#endif

....

3. 新增一個PHP_FUNCTION: 呼叫剛剛的hello_world_c_add


//呼叫自定義的c函數,來處理加法

PHP_FUNCTION(foo_hello_add) {

  php_printf("run foo_hello_add\n");

  int val1;
  int val2;
  int sum;

  //parse parameters
  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &val1,&val2 ) == FAILURE) {
      RETURN_FALSE;
  }

  php_printf("val1=%d\n",val1);
  php_printf("val2=%d\n",val2);

  sum = hello_world_c_add(val1,val2);

  RETURN_DOUBLE(sum);
}




範例: C實作/標頭檔搬到子資料夾




接著想把不同自定義的C函式庫分裝到不同的sub-folder後就爆了以下訊息:



目前這個範例卡關中...

範例: 全域變數的操作




範例: 回傳resouce



參考




  • https://github.com/jheth/hello-php-extension
  • 在 PHP Extension 中加入 static 和 dynamic library
  • Linux静态链接库与动态链接库的区别及动态库的创建
  • Linux中创建静态库和动态库
  • http://php.net/manual/en/internals2.structure.globals.php
  • https://github.com/walu/phpbook/blob/master/12.5.md


星期一, 5月 23, 2016

[PHP] php-extension編譯C++


如有c++函式庫需要處理,請在config.m4加入以下指令:

PHP_REQUIRE_CXX()

PHP_SUBST(YOUREXTENSION_SHARED_LIBADD)

PHP_ADD_LIBRARY_WITH_PATH(stdc++, "", YOUREXTENSION_SHARED_LIBADD)

PHP_ADD_LIBRARY(stdc++,EXTRA_LDFLAGS)

dnl 上面設定好了,PHP_NEW_EXTENSION的第二個參數就可以輸入 c++的檔案了,下面的例子還是C
PHP_NEW_EXTENSION(foo, php_foo.c, $ext_shared)

[PHP] config.m4 指令集筆記

記錄一下一定會忘記的php-ext常用的指令說明。

指令集

  • AC_MSG_CHECKING 
畫面輸出訊息 checking whether to enable foo extension support 
 
  • PHP_SUBST 


PHP_SUBST(XXXX_SHARED_LIBADD), 其中 XXXX 為 PHP Extension 的名稱 (全大寫)


  • PHP_ADD_LIBRARY_WITH_PATH 
  • PHP_CHECK_LIBRARY
  • PHP_ADD_INCLUDE 
  • PHP_ADD_BUILD_DIR 

  • PHP_ADD_LIBRARY_WITH_PATH 


完整指令

XXXX: 你想要載入的extension name


PHP_ADD_LIBRARY_WITH_PATH([library name], [library path], XXXX_SHARED_LIBADD)


例如我們想加入 libabc.so, 而該檔案在 /usr/lib, 則我們會加入: PHP_ADD_LIBRARY_WITH_PATH(abc, /usr/lib, XXXX_SHARED_LIBADD)

  • PHP_NEW_EXTENSION 
完整指令 PHP_NEW_EXTENSION(extname, sources [, shared [,sapi_class[, extra-cflags]]])
範例 PHP_NEW_EXTENSION(foo, foo.c bar.c baz.cpp, $ext_shared)

參考
http://tglcowcow.blogspot.tw/2008/05/php-extension-static-dynamic-library.html

星期一, 5月 16, 2016

[PHP] php extension 初試: extension parser parameter (接收參數)


接續先前的基本範例,接著要來練習怎麼接收帶入extension的參數:


zend_parse_parameters方法

zend_parse_parameters提供不同的接收變數的方式, 變數1: ZEND_NUM_ARGS() TSRMLS_CC, 二個值中間是空白,ZEND_NUM_ARGS表示傳入參數的個數 變數2: 傳入變數的格式化字串

星期五, 5月 13, 2016

[PHP] php extension 初試

拜讀完php-extension骨架練習,
如果C語言忘得差不多錄影檔有從基本的C語言開始教起:D


如果C語言已經很熟的話,可以跳至26:38秒開始

測試環境

  1. MacOSX EI
  2. MAMP (所以流程中有其他錯誤要處理一下:D)

ZVal是什麼

http://php.net/manual/en/internals2.variables.intro.php



Note:


PHP is a dynamic, loosely typed language, that uses copy-on-write and reference counting.
所有的php變數型態都是定義在一個zval的struct,並且使用copy-on-write(寫入時複製)與reference counting(來判斷變數是否還有被使用)。

Null-Terminated String



初始化 ZVAL



簡化


ZVAL設定值

ZVAL_STRING
ZVAL_LONG
ZVAL_BOOL

星期五, 5月 06, 2016

[PHP] ffmepg 相關筆記

最近工作需要用到一些audio的處理,記錄一下相關的ffmpeg討論資源。

php 使用exec 執行 ffmpeg指令
http://www.phpro.org/tutorials/Video-Conversion-With-FFMPEG.html

Binary data 處理
http://blog-en.openalfa.com/how-to-work-with-binary-data-in-php

Audio codec:
https://trac.ffmpeg.org/wiki/audio%20types

讀取WAV檔
http://www.mcpressonline.com/web-languages/easily-manage-wav-files-with-php.html

WAV file/read
https://gist.github.com/Xeoncross/3515883
https://github.com/boyhagemann/Wave

音频格式详解:WAV
http://www.aliog.com/39896.html

READ WAV
http://www.bloggingzeal.com/how-to-read-a-wav-file-with-php/

pack/unpack format
a - NUL-padded string
A - SPACE-padded string
h - Hex string, low nibble first
H - Hex string, high nibble first
c - signed char
C - unsigned char
s - signed short (always 16 bit, machine byte order)
S - unsigned short (always 16 bit, machine byte order)
n - unsigned short (always 16 bit, big endian byte order)
v - unsigned short (always 16 bit, little endian byte order)
i - signed integer (machine dependent size and byte order)
I - unsigned integer (machine dependent size and byte order)
l - signed long (always 32 bit, machine byte order)
L - unsigned long (always 32 bit, machine byte order)
N - unsigned long (always 32 bit, big endian byte order)
V - unsigned long (always 32 bit, little endian byte order)
f - float (machine dependent size and representation)
d - double (machine dependent size and representation)
x - NUL byte
X - Back up one byte
@ - NUL-fill to absolute position

a一个填充空的字节串
A一个填充空格的字节串
b一个位串,在每个字节里位的顺序都是升序
B一个位串,在每个字节里位的顺序都是降序
c一个有符号char(8位整数)值
C一个无符号char(8位整数)值;关于Unicode参阅U
d本机格式的双精度浮点数
f本机格式的单精度浮点数
h一个十六进制串,低四位在前
H一个十六进制串,高四位在前
i一个有符号整数值,本机格式
I一个无符号整数值,本机格式
l一个有符号长整形,总是32位
L一个无符号长整形,总是32位
n一个16位短整形,“网络”字节序(大头在前)
N一个32位短整形,“网络”字节序(大头在前)
p一个指向空结尾的字串的指针
P一个指向定长字串的指针
q一个有符号四倍(64位整数)值
Q一个无符号四倍(64位整数)值
s一个有符号短整数值,总是16位
S一个无符号短整数值,总是16位,字节序跟机器芯片有关
u一个无编码的字串
U一个Unicode字符数字
v一个“VAX”字节序(小头在前)的16位短整数
V一个“VAX”字节序(小头在前)的32位短整数
w一个BER压缩的整数
x一个空字节(向前忽略一个字节)
X备份一个字节
Z一个空结束的(和空填充的)字节串

星期五, 4月 29, 2016

[PHP] Composer 教學筆記

現在寫php一定要會用的套件管理工具composer

安裝

參考一下這篇
http://iambigd.blogspot.tw/2013/07/php-composer.html

快速安裝使用

1. 首先要在專案下建立composer.json,加入你要引用的套件(管理套件相依性)

{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}

2. 然後執行composer install

3. 接著就會在專案下產生composer.lock檔案以及vendor目錄

composer.lock

在首次安裝套件完畢後,會產生這個檔案,裡面記錄了所安裝套件的資訊。這個檔案的真正作用是:如果目錄中有這個檔案,執行安裝時,就不會去搜尋更新的版本,而是依照這個檔案中記錄的版本來安裝。這個設計很重要,因為新版的套件很有可能與目前使用的版本不相容,如果不是使用同樣版本,很難保證系統的穩定。過去在使用pear來管理套件時,如果不注意,就有可能發生升級導致的慘劇。

vendor目錄(預設目錄)

主要含以下內容

  • vender/autoload.php
只要引用這個檔案,就可以載入套件中所有對外公開的類別。

require 'vendor/autoload.php';
  • vender/composer
自動載入的載入器與快取檔

  • 各套件資料夾目錄
依造命名規則/

場景應用注意(From 大澤小木鐵phpconf簡報):


  1. Git只需要加入composer.json 與composer.lock,方便其他成員使用
  2. 請由專案負責人進行composer的第一次安裝與之後的更新
  3. 不要將vendor資料夾送入Git,其他團隊成員應該只要透過composer install安裝
  4. Library的composer.lock不要加入Git




參考

  1. https://speakerdeck.com/jaceju/begining-composer
  2. http://ithelp.ithome.com.tw/question/10136653


星期日, 12月 20, 2015

[php] htaccess: Options not allowed here 異常

今天在架CI的舊專案時,發現以下error。

[Fri Dec 04 15:51:36.019560 2015] [core:alert] [pid 19393] [client 10.211.55.2:58540] /var/www/<專案名稱>/.htaccess: Options not allowed here

解決方法是把原本htaccess下面的Options設定先註解掉就好了,
不知為何先前要寫這一行XD

#Options +FollowSymLinks
        
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(system|application).*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?/$1 [L]



星期六, 7月 11, 2015

[CI] 記錄一下CI框架新手功能

記錄一些CI框架Seed常用的功能手記,讓日後可以快速回憶 :D
雖然已經是被很多人放棄的技術,不過還是有他方便的地方XD

測試版本

CI 2.x

設定起始的base url

Just overwrite the line in config/config.php with the following:
$config['base_url']    = 'http://'.$_SERVER['HTTP_HOST'].'/';
If you are using the sub folder you can use following code:
$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = "$root";

設定資料庫


application/config/database.php:

設定啟動的控制器


打開application/config/routes.php:
$route['default_controller'] = 'index';

設定啟動時載入相關的helper


打開application/config/autoload.php:
// $autoload['helper'] = array();
$autoload['helper'] = array('form','url','assets','images','load_view_helper');

星期二, 11月 18, 2014

[PHP] 西元日期轉中文年月日

如果有需要將西元日期轉換的話,可以不用拆解字串的方式。
可參考內建的date函數即可

echo date('Y年n月d日',strtotime('2014-11-18')); 

星期五, 5月 16, 2014

[CI] 使用CI框架打造REST Server

現在已經是REST API的時代XD,幾乎每個語言都有支援快速打造REST框架的方法。
剛好最近在用CI,果然Github就有資源啦

https://github.com/philsturgeon/codeigniter-restserver

作者還有詳細的說明,請參照他的部落格

Working with RESTful Services in CodeIgniter

看不慣英文也有對岸的工程屍翻譯XD

使用CodeIgniter 创建 RESTful 服务 REST API【原创译文】


星期五, 4月 25, 2014

[PHP,jQuery] 實作圖片旋轉與儲存

如果你的網站有圖片需要旋轉與儲存的需求,可以參考這個範例外掛:D

UI:
https://code.google.com/p/jquery-rotate/

Server:
//define image path
$filename="image.jpg";

// Load the image
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

//and save it on your server...
file_put_contents("myNEWimage.jpg",$rotate);


其他你感興趣的文章

Related Posts with Thumbnails