Skip to content

Instantly share code, notes, and snippets.

@pigfly88
pigfly88 / docker_compose_set_ip.yml
Created September 23, 2020 01:57
docker-compose-set-ip
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'
@pigfly88
pigfly88 / download_file.php
Created September 16, 2020 03:43
Download remote file straight to client
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 = [
// 下划线转驼峰 出自Doctrine Inflector
function camelize($word) {
return lcfirst(str_replace([' ', '_', '-'], '', ucwords($word, ' _-')));
}
@pigfly88
pigfly88 / check_php_process.php
Created October 10, 2019 06:13
check php process
<?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);
@pigfly88
pigfly88 / doctrine_mysql_server_gone_away.php
Created September 19, 2019 06:26
doctrine fix mysql server gone away
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
@pigfly88
pigfly88 / million_data_export_to_csv.php
Last active September 2, 2019 10:47
million data export to csv
<?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 = [