PHP Webã¢ããªã±ã¼ã·ã§ã³ããéåæã«ã³ãã³ããå®è¡ããã©ã¤ãã©ãªãã¤ããã¾ããã
ãããªã®ä½ãã¾ããã
Webã®ããã»ã¹ããéãå¦çãå®è¡ãããã®ã ãã©ããã
PHPã§CSVãã¡ã¤ã«ãªã©ããä¸æ¬ã§å¤§éã®ãã¼ã¿æå ¥ãè¡ãããã¨ããããã¾ãã ãããWebã¢ããªã±ã¼ã·ã§ã³ã®ããã»ã¹ã§ãããã¨ããã¨ãå¦çæéãé·ããããã ãããããã»ã¹ãã¿ã¤ã ã¢ã¦ããã¦ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ããå°ã£ããã®ã§ãã
ããããã¨ãã代ããã«ã³ãã³ãã©ã¤ã³ã®ããã°ã©ã ã¨ãã¦å®è£ ããããããã§ãããä»»æã®ã¿ã¤ãã³ã°ã§å¦çãããå ´åãã³ãã³ãå®è¡ãã以ä¸ãµã¼ãã«ã¿ã¼ããã«ã§ãã°ã¤ã³ã§ããæè¡è ãããã¼ã¿æå ¥ä½æ¥ãã§ããªããªã£ã¦ãã¾ãã¾ãã ãã£ã¨ã ãã«ã§ãã§ããããã«ããã£ã±ãWebã¢ããªã±ã¼ã·ã§ã³ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã欲ãããªãã®ã人æ ã§ãã
Webã¢ããªããéåæã«ã³ãã³ããå®è¡ãã
ãã®è¦ä»¶ãæºããç°¡åãªæ¹æ³ã¯ã以ä¸ã®ãããªã³ã¼ãã§Webããã»ã¹ããå¤é¨ã³ãã³ããããã¯ã°ã©ã¦ã³ãã§å®è¡ãããã¨ã§ãã
exec("php yourcommand.php > /dev/null &");
ãããããã¨ã§å®è¡ã³ãã³ãã¯éåæã«ããã¯ã°ã©ã¦ã³ãã§åä½ããWebã®ããã»ã¹ã¯ã³ãã³ãã®å¦çå 容ã«ããããããå³æã¬ã¹ãã³ã¹ãè¿ããã¨ãã§ãã¾ãã
ãã ããã ã¨ã以ä¸ã®ãããªä¸æºãããã¾ãã
- å¤é¨ã³ãã³ãã®ã¨ã©ã¼å¦çãèãããã¦ããªããã³ãã³ããã¨ã«ããããå é¨ã§ä½ããã®å®è£ ãããå¿ è¦ãããã
- å®è¡éå§ããã³ãã³ãã®ããã»ã¹ãWebããã»ã¹å´ããé¢ä¸ãããã¨ãã§ããªãã
ãããããã¨ããã¾ãæ±ãããã«ãã¸ã§ããã¥ã¼ã¨ã³ã¸ã³ããDBãªã©ã使ã£ãã¿ã¹ã¯ãããã»ã¹ã管çããä»çµã¿ã¯ãã§ã«ããã¨æãã¾ãã ã§ãããã¾ã§æéããããããæ§æãè¤éã«ããããªãã
ã¡ãã£ã¨ã ãçºå±ããã¦ã¿ã¾ãã
ã¨ããããã§ä½ã£ãã®ãã
ã¤ã³ã¹ãã¼ã«ã¯Composerã§ä»¥ä¸ã®ããã«composer.json
ãä½æãã¦
{
"require": {
"kohkimakimoto/background-process": "1.1.*"
}
}
ã¤ã³ã¹ãã¼ã«ã³ãã³ããå®è¡ã
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install
使ãæ¹ã¯ãå®è¡ãããã³ãã³ããã³ã³ã¹ãã©ã¯ã¿ã«æå®ãã¦ãªãã¸ã§ã¯ããçæããå¾runã¡ã½ãããå®è¡ããã ãã§ãã
use Kohkimakimoto\BackgroundProcess\BackgroundProcess;
// Creates instance and set command string to run at the background.
$process = new BackgroundProcess("ls -l > /tmp/test.txt");
// Runs command, and it returns immediately.
$process->run();
// Get key identified the process.
$key = $process->key();
$process->key()
ã§ããã»ã¹ãèå¥ããä¸æãã¼ãåå¾ã§ãã¾ãã
ããã¯ãã¨ã§å®è¡ããã³ãã³ããå®è¡ä¸ã§ããããªã©ã確èªããã®ã«ä»¥ä¸ã®ããã«ä½¿ãã¾ãã
use Kohkimakimoto\BackgroundProcess\BackgroundProcess;
$manager = new BackgroundProcessManager();
$process = $manager->loadProcess($key);
// If a process specified by the key dosen't exist, loadProcess method returns null.
if (!$process) {
echo "Not working process $key";
} else {
$meta = $process->getMeta();
echo $meta['created_at']; // (ex 2013-01-01 10:00:20
echo $meta['pid']; // (ex 1234
}
ã¾ããã³ãã³ããã¨ã©ã¼ã«ãªã£ãå ´åããã©ã«ãã§ä¸ã®ãã¹ã®ãã°ãã¡ã¤ã«ã«ã¨ã©ã¼ãã°(æ¨æºã¨ã©ã¼åºå)ãåºåãã¾ãã
/tmp/php/background_process/err.log
å é¨ã®ä½ã
åè¿°ããããã«ãæ軽ã«ä½¿ããããã«ãããã£ãã®ã§DBãªã©ã¯ä½¿ã£ã¦ãã¾ããã
BackgroundProcessã¯runã¡ã½ãããå®è¡ããã¨ãããã©ã«ãã§/tmp/php/background_process/
é
ä¸ã«ã³ãã³ããã¨ã«ãPHPãã¡ã¤ã«ã¨JSONãã¡ã¤ã«ãåºåãã¾ãã
PHPãã¡ã¤ã«ã¯ã³ã³ã¹ãã©ã¯ã¿ã§æå®ããã³ãã³ãã®å®è¡ãè¡ãã¹ã¯ãªããã§ãJSONãã¡ã¤ã«ã¯ããã»ã¹IDãªã©ã®ã¡ã¿ãã¼ã¿ãä¿æãã¦ãã¾ãã
ãããã®ãã¡ã¤ã«ãå©ç¨ãã¦ã³ãã³ãå®è¡ãã¨ã©ã¼å¦çãããã»ã¹IDã®åå¾ãªã©ãè¡ã£ã¦ãã¾ãã
ã³ãã³ããæ£å¸¸çµäºããã¨ããããã®ãã¡ã¤ã«ã¯èªååé¤ããã¾ãã
ã·ã¼ã±ã³ã¹å³ã«ããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã