PHP

Last Edited Time
Feb 9, 2022 06:58 AM
date
Jan 3, 2018
slug
php
status
Published
tags
PHP
Notebook
Command
summary
早期 PHP 工作笔记
type
Post

replace map string

str_replace([" ", "#"],"+",$mapAddress)

Magento pwd

/var/www/api/app/code/local/Rs/Ext/Model/Api2

/var/www/api/app/code/core/Mage/Api2/Model/Server.php
if($e->getMessage()=='Invalid request method'){
   $response->setHeader('HTTP/1.0', 204, true);
   $response->sendResponse();
}

local/Rs/Ext/Model/Api2/Login2/Rest/Guest/V1.php
local/Rs/Ext/Model/Api2/Login2.php

grep -r 'ordlst' app/code
vig app/code/local/Rs/Ext/etc/api2.xml
vig app/code/local/Rs/Ext/Model/Api2/Orderhistorylist/Rest/Customer/V1.php

grep -r 'preview' app/code/local/Rs
vig app/code/local/Rs/Ext/etc/api2.xml
vig app/code/local/Rs/Ext/Model/Api2/Productreview2/Rest/Customer/V1.php
vig app/code/local/Rs/Ext/Model/Api2/Productreview2/Rest/Guest/V1.php
php n98-magerun.phar dev:console

/var/www/api/var/log/

format number

$mins = sprintf("%02d", $mins-60);
 number_format($grandtotal,2)

sprintf("%02d", $mins-60);

var_dump to js

echo '<script type="text/javascript">console.log('.json_encode($postBody).')</script>';

enable php error reporting

error_reporting(E_ERROR);
error_reporting(E_ALL | E_STRICT);
error_reporting(-1);
ini_set('display_errors', 1);

write log

file_put_contents("oauth.log", API[ACTION[$action]]."\n", FILE_APPEND | LOCK_EX);

get session by id

session_id($_GET['session_id']);
session_start();
//var_dump(session_id());

make time

$selectedTime = "9:15:00";
$endTime = strtotime("+15 minutes", strtotime($selectedTime));
echo date(H:i:s', $endTime);

$time = strtotime($dateWithTimeZone);
$time = strtotime($dateInUTC.' UTC');
$dateInLocal = date("Y-m-d H:i:s", $time);

php receive post with content type json

if($_SERVER['CONTENT_TYPE']=="application/json"){
  $postObj = json_decode(file_get_contents("php://input"), true);
} else {
  $postObj = $_POST;
}

php random string

$randomString = substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($randomStringLength/strlen($x)) )),1,$randomStringLength);

net::ERR_INCOMPLETE_CHUNKED_ENCODING

//http://blog.csdn.net/p569354158/article/details/8120177
//buffer flow output_buffering, fastcgi_buffer,  proxy_buffering

ob_end_flush(); // 冲刷出(送出)输出缓冲区内容并关闭缓冲
// ob_end_clean() //得到当前缓冲区的内容并删除当前输出缓。
// ob_get_status(true) //得到所有输出缓冲区的状态
// ob_get_level() //返回输出缓冲机制的嵌套级别
ob_implicit_flush();//disable system output buffer (don't need to call flush())
ini_set('output_buffering', 1024 * 4); //set output buffer size
header('X-Accel-Buffering: no'); // disable nginx proxy buffer, and make sure nginx config didn't proxy_ignore_headers to ignore this setting

// V_1.2
//ob_start(); //this function will make ob_flush() and flush() not working (don't know reason)
echo str_repeat('a', 1024*4); //for fastcgi_buffer, becasue we cannot use flush() to clear fastcgi_buffer

echo '<br>php max_execution_time:'.json_encode(ini_get('max_execution_time'));
echo '<br>php safe_mode:'.json_encode(ini_get('safe_mode'));
for($i=0; $i<40; $i++){
  echo "<br>{$i}<br>";
  //ob_flush(); //no need if userspace output buffer is disabled
  //flush(); //no need if system output buffer is disabled
  sleep(1);
}

//php max_execution_time
//php-fpm request_terminate_timeout
//nginx: gzip, chunked_transfer_encoding, fastcgi_read_timeout, proxy_cache_path