ラベル PHP の投稿を表示しています。 すべての投稿を表示
ラベル PHP の投稿を表示しています。 すべての投稿を表示

2013年3月9日土曜日

PHP開発用emacs設定

php-mode, flymake


geben

ステップ実行に頼らずに生活できるようになりたいけど。
/etc/php.d/xdebug.ini
zend_extension=/usr/lib/php/modules/xdebug.so
xdebug.remote_enable=yes
xdebug.remote_autostart=no
xdebug.remote_host=localhost
xdebug.remote_port=9000

phpファイルにxdebug_break()
リクエストにXDEBUG_SESSION_STARTをつける


ctags

M-.
(defun run-refresh-tag()
(interactive)
(shell-command "cd /path/to/source; ctags -e -R --php-kinds=cfd &"))

yasnippet-php-mode

標準ライブラリの関数の引数の順序がいつもわからなくなるので助かる。

その他



;; 開いてるファイルをphpunitする
(defun run-php-unit()
(interactive)
(shell-command (concat "phpunit " (buffer-file-name) " &")))

;; 選択したリージョンをevalする

(defun php-eval-region ()
(interactive)
(shell-command-on-region (region-beginning) (region-end) "php ~/.emacs.d/php-eval-region/eval.php"))


~/.emacs.d/php-eval-region/eval.php
<?php
$region = file_get_contents('php://stdin');
if (strlen($region) > 0) {
  ob_start();
  eval('$_tmp_ = ' . $region . ';');
  $output = ob_get_contents();
  ob_end_clean();
  if (strlen($output) > 0) {
   print($output . "\n");
  }
  print_r($_tmp_);
}


まだ、これくらいしか設定してない。

2013年3月8日金曜日

MySQLでinsert, updateを大量に実行したいとき

PHP+MySQLで同じテーブルに大量のinsertやupdateを行う場合に、
1回ずつ実行すると遅いのでまとめてinsertすると早くなります。

INSERT INTO table (id, name) VALUES (1, 'name1');
INSERT INTO table (id, name) VALUES (2, 'name2');
....

のような場合、

INSERT INTO table (id, name) VALUES (1, 'name1'), (2, 'name2'), ...;
のようにvaluesを複数にしてまとめて実行するようにします。


 updateの場合にはON DUPLICATE KEY UPDATEをつけたinsertを実行すれば同様の効果が得られます。

UPDATE table set name = 'name1' where id = 1;
UPDATE table set name = 'name2' where id = 2;

を以下のようにします。

INSERT INTO table (id, name) VALUES (1,'name1'), (2, 'name2')
ON DUPLICATE KEY UPDATE name = VALUES(`name`)';

UPDATE文をたくさんつなげた長いSQLを作って実行すると、
接続回数が減るためか一応早くなりますが大きな効果は得られません。


初投稿なので練習も兼ねて適当な感じで終わりです。