This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
cgmid: | |
image: yiisoftware/yii2-php:7.1-apache | |
build: . | |
volumes: | |
- ~/.composer-docker/cache:/root/.composer/cache:delegated | |
- ./:/app:delegated | |
ports: | |
- '8002:80' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function downloadFile($fileUrl) | |
{ | |
$isRemoteFile = null === parse_url($fileUrl, PHP_URL_HOST) ? false : true; | |
$fileName = $isRemoteFile ? ltrim(parse_url($fileUrl, PHP_URL_PATH), '/') : pathinfo($fileUrl, PATHINFO_BASENAME); | |
// 获取文件大小 | |
if ($isRemoteFile) { | |
$ch = curl_init($fileUrl); | |
$options = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 下划线转驼峰 出自Doctrine Inflector | |
function camelize($word) { | |
return lcfirst(str_replace([' ', '_', '-'], '', ucwords($word, ' _-'))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// check php process is running by pid | |
$pid = 16591; | |
$isRunning = `ps -p $pid -o pid=`; | |
var_dump($isRunning); | |
// get running php process pid list | |
$pidList = `ps h -o pid -C php`; | |
var_dump($pidList); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
$this->em->getConnection()->fetchAll("select * from tbl where id=1"); | |
sleep(30); // set this bigger than mysql wait_timeout | |
$this->em->getConnection()->fetchAll("select * from tbl where id=2"); // and then you will see mysql has gone away here | |
} catch (DBALException $exception) { // don't worry, let's catch this exception and reconnect to mysql | |
if (false !== strpos($exception->getPrevious()->getMessage(), 'server has gone away')) { | |
$this->em->getConnection()->close(); | |
$this->em->getConnection()->->connect(); | |
// or use $this->container->get('doctrine.orm.entity_manager') if you don't have $this->em |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('Content-Description: million-data-export'); | |
header('Content-Type: application/csv'); | |
header("Content-Disposition: attachment; filename=million-data-export.csv"); | |
header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); | |
$dsn = 'mysql:dbname=data-warehouse;host=127.0.0.1'; | |
$user = 'root'; | |
$password = '123'; | |
$options = [ |