忍者ブログ

カウンター

プロモーション

カレンダー

03 2024/04 05
S M T W T F S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

AntinomyMy の実験室

   私のWEBアプリ実験室です!

ブログ内検索

楽天でお買い物

twitter

最新トラックバック

最新コメント

忍者アナライズ

ウェザーニュース

バーコード

本を買う

アクセス解析

Google+

[PR]

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。


No Image

CRON が動いてるかPHPのメール送信使えば楽じゃん!っていう話題

PHP の調べ物

CRON って誰権限で動いてるだ?!
これ、ちゃんと動いてるのか?
そういった事に困るとき、
ふと思った。。。

ドメインがあってメール送信できる場合には、
適当に自身の持ってるメアドにCRONが動いたときに送ればいいじゃん!
っていう。


php -r "mail('自分のメアド','test cron','test msg','好きなアドレス@CRONが動いてるドメインのメアド');"


こんだけぇ~でいい。

後は、これをCRON で * * (~~~ 好きな時間を指定して~~~略~~~~ ~~~)
+上記の一行入れれば、PHPが動く環境なら適当なメッセージが飛び込んでくる。

; で区切れば複数できるだろうし、
なんとかんる!

こりゃ便利。

拍手[0回]

PR

No Image

PHP のextension_dir の相対パス (relative path)はApache のbin からのパス!!!

PHP の調べ物

Apache Module で呼び出すPHP のextension_dir の相対パス(relative path)
についてのメモ

※Windows もLinux も一緒であるか分からないです※
Windows でApache とPHP の入っているディレクトリごと
好きな場所に移動して、バッチファイルから実行したいので
迷った時のメモです。


PHP の
extension_dir のパス
Windows なら
C:\xxxx\xxxx

とか絶対パスで書く方法しかこれまで使ったことがなかったので
相対パスだとどうなるか、あれこれやっても動かないので困っていました。

もしかして・・・と思い、
Apache のbin から見た相対的なアドレスを書いてみました。

xxx\Apache\bin\
(httpd.exe のあるフォルダ)

xxx\php\ext\
(拡張のフォルダ)
があったとします。

そうすると、php.ini では、
extension_dir
は、php のext のフォルダを
..\..\php\ext
と書きます。

つまり
extension_dir = "..\..\php\ext"

と書く事になります。

一応、後から書いたメモなので、どうだったか定かですが、
Apche はModule版のPHP を使っています。

httpd.conf には、上記のパスの作りであると
PHPINIDir "..\..\php"
としています。

また、
Module 版だとApache のconfig (httpd.conf)で
php_admin_value が使えるので
php_admin_value extension_dir = "..\..\php\ext"
としてもいいですが、
実行時の設定でデフォルトの方の設定には反映されないです。

なんとも言い難いのでやっぱりPHPのphp.ini に書くべきだと思います。


そして気持ちの悪い作りの問題ですが、
これをすると、きっと間違いなく、

プロシージャエントリポイントxxx_xxx_xxxが
ダイナミックリンクライブラリxxx.dllから見つかりませんでした

と出てくると思います、これが出たらパスが通った証拠なのですが、
Apache から見て、PHP のモジュールが見えないと、
Apache のモジュール版のPHP は動いていることにならないみたいなのです。

ここで気持ちが悪いのですが、
Apache のbin つまり、apache.exe のあるフォルダに
PHP のphp.exe のあるフォルダにある、xxx.dllをコピーして入れます。

当方の場合、何度か聞かれましたが、
extension の読み込む量やら状況に応じて、
その聞かれる数は違うと思います。

聞かれる度にxxx.dllをコピーしたらエラーを聞かれず、
指定したextension を全て
phpinfo() から確認することが出来ました。



何とも厄介ですが、extension_dir の相対パス での指定は成功!した訳です。



うーん、微妙だけど、現在のApache とPHP ではこの設定しかないみたいです。
ちなみに、php のバージョンは7.2 で確認をしました(Windows 版です)。


お粗末なメモでした<_ _>

拍手[1回]


No Image

php7.2 で確認。php_opcache はZend OPcache 、つまりextension でなくzend_extension だった。

PHP の調べ物

OPcacheは、PHP7.2 のWindows ローカルでようやく使い出したので、
それ以前は知らない。

なぜ使おうかと思ったかと言うと、
OPcache はPHP7.1からかなり早くなったらしい(余談だけど)。

php.ini

exteinsion の記述になぜか
;extension=php_opcache
という注釈化された記述がない

おかしいな?

ext フォルダに
php_opcache.dll

があるんだけど

試しに
extension=php_opcache
と記述

動かない!!!

意味が分からないのでネットで調べると
zend_extension=

"xxx\php_opcache.dll"
が読み込まれる設定の記述が

試しにやってみる
zend_extension="ext\php_opcache.dll"

動かない・・・

うん?!
コマンドラインCli の方で実行すると、どうもext にext のフォルダがない様な趣旨のエラー

もともと、extension のフォルダの中身を、見ているみたい。
バッチファイル(.bat)によってコマンドとして、php.exe を-S として
呼び出す様にして使っているので、
extension_dir = "./ext"
としてあるので、ここを
zend_extension
の設定は見ている様だ。

なんかややこしいが


zend_extension="php_opcache.dll"
としたら
なんと動いた!

後はphp.ini に非常に多くの設定があるの

[opcache]
zend_extension= "php_opcache.dll"
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=128
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 1000000 are allowed.
opcache.max_accelerated_files=10000
; The maximum percentage of "wasted" memory until a restart is scheduled.
opcache.max_wasted_percentage=5
; When this directive is enabled, the OPcache appends the current working
; directory to the script key, thus eliminating possible collisions between
; files with the same name (basename). Disabling the directive improves
; performance, but may break existing applications.
;opcache.use_cwd=1
; When disabled, you must reset the OPcache manually or restart the
; webserver for changes to the filesystem to take effect.
;opcache.validate_timestamps=1
; How often (in seconds) to check file timestamps for changes to the shared
; memory storage allocation. ("1" means validate once per second, but only
; once per request. "0" means always validate)
opcache.revalidate_freq=2
; Enables or disables file search in include_path optimization
;opcache.revalidate_path=0
; If disabled, all PHPDoc comments are dropped from the code to reduce the
; size of the optimized code.
;opcache.save_comments=1
; Allow file existence override (file_exists, etc.) performance feature.
;opcache.enable_file_override=0
; A bitmask, where each bit enables or disables the appropriate OPcache
; passes
;opcache.optimization_level=0xffffffff
;opcache.inherited_hack=1
;opcache.dups_fix=0
; The location of the OPcache blacklist file (wildcards allowed).
; Each OPcache blacklist file is a text file that holds the names of files
; that should not be accelerated. The file format is to add each filename
; to a new line. The filename may be a full path or just a file prefix
; (i.e., /var/www/x  blacklists all the files and directories in /var/www
; that start with 'x'). Line starting with a ; are ignored (comments).
;opcache.blacklist_filename=
; Allows exclusion of large files from being cached. By default all files
; are cached.
;opcache.max_file_size=0
; Check the cache checksum each N requests.
; The default value of "0" means that the checks are disabled.
;opcache.consistency_checks=0
; How long to wait (in seconds) for a scheduled restart to begin if the cache
; is not being accessed.
;opcache.force_restart_timeout=180
; OPcache error_log file name. Empty string assumes "stderr".
;opcache.error_log=
; All OPcache errors go to the Web server log.
; By default, only fatal errors (level 0) or errors (level 1) are logged.
; You can also enable warnings (level 2), info messages (level 3) or
; debug messages (level 4).
;opcache.log_verbosity_level=1
; Preferred Shared Memory back-end. Leave empty and let the system decide.
;opcache.preferred_memory_model=
; Protect the shared memory from unexpected writing during script execution.
; Useful for internal debugging only.
;opcache.protect_memory=0
; Allows calling OPcache API functions only from PHP scripts which path is
; started from specified string. The default "" means no restriction
;opcache.restrict_api=
; Mapping base of shared memory segments (for Windows only). All the PHP
; processes have to map shared memory into the same address space. This
; directive allows to manually fix the "Unable to reattach to base address"
; errors.
;opcache.mmap_base=
; Enables and sets the second level cache directory.
; It should improve performance when SHM memory is full, at server restart or
; SHM reset. The default "" disables file based caching.
;opcache.file_cache=
; Enables or disables opcode caching in shared memory.
;opcache.file_cache_only=0
; Enables or disables checksum validation when script loaded from file cache.
;opcache.file_cache_consistency_checks=1
; Implies opcache.file_cache_only=1 for a certain process that failed to
; reattach to the shared memory (for Windows only). Explicitly enabled file
; cache is required.
;opcache.file_cache_fallback=1
; Enables or disables copying of PHP code (text segment) into HUGE PAGES.
; This should improve performance, but requires appropriate OS configuration.
;opcache.huge_code_pages=1
; Validate cached file permissions.
;opcache.validate_permission=0
; Prevent name collisions in chroot'ed environment.
;opcache.validate_root=0
こんな感じで設定したら

Zend OPcache

Opcode Caching Up and Running
Optimization Enabled
SHM Cache Enabled
File Cache Disabled
Startup OK
Shared memory model win32
Cache hits 0
Cache misses 1
Used memory 18735736
Free memory 115481992
Wasted memory 0
Interned Strings Used memory 193336
Interned Strings Free memory 8195272
Cached scripts 1
Cached keys 1
Max keys 16229
OOM restarts 0
Hash keys restarts 0
Manual restarts 0
DirectiveLocal ValueMaster Value
opcache.blacklist_filename no value no value
opcache.consistency_checks 0 0
opcache.dups_fix Off Off
opcache.enable On On
opcache.enable_cli On On
opcache.enable_file_override Off Off
opcache.error_log no value no value
opcache.file_cache no value no value
opcache.file_cache_consistency_checks 1 1
opcache.file_cache_fallback 1 1
opcache.file_cache_only 0 0
opcache.file_update_protection 2 2
opcache.force_restart_timeout 180 180
opcache.inherited_hack On On
opcache.interned_strings_buffer 8 8
opcache.log_verbosity_level 1 1
opcache.max_accelerated_files 10000 10000
opcache.max_file_size 0 0
opcache.max_wasted_percentage 5 5
opcache.memory_consumption 128 128
opcache.mmap_base no value no value
opcache.opt_debug_level 0 0
opcache.optimization_level 0x7FFFBFFF 0x7FFFBFFF
opcache.preferred_memory_model no value no value
opcache.protect_memory 0 0
opcache.restrict_api no value no value
opcache.revalidate_freq 2 2
opcache.revalidate_path Off Off
opcache.save_comments 1 1
opcache.use_cwd On On
opcache.validate_permission Off Off
opcache.validate_timestamps On On
こんな感じだった。

セオリー的な設定とかある様だが、
ネット上の検索や公式では
http://php.net/manual/ja/opcache.installation.php
以下


opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

とりあえず、PHP7.2 に
なぜかPHP5x のバージョンのphp.ini になかったOPcache項目が
注釈で書かれているし、なかった項目や、なくなった項目とかも
多分ありそうなので、見直した方がいいかなと思う。

インクルード先の話は戻るが、
dell 本体の名前を、php_zend_opcache.dll
とか、そういうリネーム(普通しない)にするか、
それともインクルード先として読みに行くext フォルダの中に
子のフォルダを適当な区別できる名前(zend とかOutside)のフォルダの中に
入れてくれるか、どっちかをしないと、zend_extensionの分類で
インクルードしていることが分かり難い。

フルパスでない場合にはextension_dir を
zend_extension は見ているとか、
説明どこかにあるのか(単純に無い?)は知らないが、直感的にはわからない



悩んでたのでメモにしたら長くなったブログでした

お粗末<_ _>

拍手[0回]


No Image

PHP7 APCu の設定

PHP の調べ物


PHP info を見て、同じコンパイル方法で、
自身のPHP のバージョンのPECL のAPCu を入れる
https://pecl.php.net/package/APCu

当方の場合、Windows の64bit でPHP7.2.2 の
https://pecl.php.net/package/APCu/5.1.10/windows
7.2 Thread Safe (TS) x64
を使用した。
自身のPHPにあったものを使う

どうも、PHP5.5や5.6 だと、APC とAPCu がかぶっているらしいので、

apcu_bc というPECL を使わないといけないらしい
https://pecl.php.net/package/apcu_bc


しかし、今回、当方が使うのはPHP7系なので、apcu_bc という
apc の機能をつぶすものは入れる必要はない

入れたら
php.ini の設定だが
まず、エクステンションを読み込む。
PHP7からは、Linux でもWindows でも、
xxx.dll や、xxx.so の様に拡張子の記述の必要がなくなっている!

なので、php.ini に
extension=php_apcu
と書いて、拡張の設定をphp.ini の一番最後の方にでも、
CLi から使うならphp.ini に

apc.enable_cli=1
追加する

例えばネットでみる設定は
[apcu]
apc.enabled=1
apc.shm_size=32M
apc.ttl=7200
apc.enable_cli=1
apc.serializer=php

などであった。

当方の場合、キャッシュのサイズを自動にしたかったのだが、
自動ができるか?と思い、-1 を設定してみたが、
自動にはならず、0や-1 を設定すると、強制的に32M に戻されてしまう様だ



CLi の場合の確認は、
php.exe の該当のコマンドで
php.exe -i | grep

とすれば
~ 略 ~

apcu
APCu Support => Enabled
Version => 5.1.10
APCu Debugging => Disabled
MMAP Support => Disabled
Serialization Support => php
Build Date => Feb 16 2018 07:38:57
Directive => Local Value => Master Value
apc.coredump_unmap => Off => Off
apc.enable_cli => On => On
apc.enabled => On => On
apc.entries_hint => 4096 => 4096
apc.gc_ttl => 3600 => 3600
apc.preload_path => no value => no value
apc.serializer => php => php
apc.shm_segments => 1 => 1
apc.shm_size => 32M => 32M
apc.slam_defense => On => On
apc.smart => 0 => 0
apc.ttl => 7200 => 7200
apc.use_request_time => On => On
apc.writable => /tmp => /tmp

と出てくれば成功。



そして
あとから説明をする、APCやAPCu をGUI で表示するのならば、
;extension=gd2

extension=gd2

そしてこれもはじめ悩んだが、
phpinfo() の関数でapcu の項目が、GUIのこの関数では出てこない!
output_buffering = Off

としよう、値が入っていると動かない!!!


また、最後に前途のGUI でAPC もしくはAPCu の使用量等や、
設定の項目を閲覧するツールは
PHP7 以前のものを使っていると古いのか、閲覧できなかった。

なので新しいものを
https://raw.githubusercontent.com/krakjoe/apcu/master/apc.php

からダウンロードしたら、あっさり閲覧できた。



以上、メモでした
お粗末<_ _>


大事な追伸!!!(2020年5月3日)
Windows版の拡張を使っていて気が付いたのですが、
同時にコンパイルされて(して)出来たバージョンの拡張には、
.dll を付けなくとも、phpinfo() で拡張がされたことになりますが、
どうも、後からPECL としてダウンロードしたものであると、
.dll を付けないと認識しない気がする。。。。

なので、何処かの誰かがcompileして、一式dll も入っているものでも、
良く分からないけれど、APCu ならば、.dll は必要で、
extension=php_apcu
だと動かず。。。

extension=php_apcu.dll
でないといけない気がする。。。

なんなんだ、この謎仕様は?

お粗末<_ _>

拍手[0回]


No Image

MySQL 同じテーブルで同じレコードを重複させて結合させる UNION ALL とSELECT に AS

PHP の調べ物

SELECT を使って、同じテーブルの内容で
レコードをかぶってる状態で取得したかった。

たとえば1回のクエリーを送るだけで、
ランキングで自身+100件とか取得出来れば楽だ(プロシージャーをCALLする等)

それではじめは、SELECT に as 適当な名前(例では t_colom)
にして、余計なカラムで順位をつけて取得するみたいなことをしていた。
(実験だから、自身のIDが下に結合されてついてます)


SELECT '1' as t_column, user_id FROM `xxx_table` LIMIT 3
UNION
SELECT '2' as t_column, user_id FROM `xxx_table`
WHERE
`user_id`='0003';
t_columnuser_id
1 0001
1 0002
1 0003
2 0003

しかし、UNION ってALL をつけると、重複してくれて、すべてを取得できる。


SELECT user_id FROM `xxx_table` LIMIT 3
UNION ALL
SELECT user_id FROM `xxx_table`
WHERE
`user_id`='0003';
 
user_id
0001
0002
0003
0003


知らなかった・・・w

UNION DISTINCT がデフォルトで、
UNION って書く場合には、DISTINCT が指定されていることになっている。
知らなかった・・・ 知らなかった・・・

はじめ覚えた本にそんな事が書かれてなかった本で
それをずっと信じていた。

いっぱいあちこち見てみるもんだなぁ・・・

拍手[0回]


[PR]