(Apply for files handler)
Enter command line
php -r “echo session_save_path();”
If got empty result, try
ls /tmp/sess_*
You can edit session file on server and get result on client by web browser (View cookie to get session file ID)
(Apply for files handler)
Enter command line
php -r “echo session_save_path();”
If got empty result, try
ls /tmp/sess_*
You can edit session file on server and get result on client by web browser (View cookie to get session file ID)
mysql> show grants for ‘vietnam’@’192.168.1.114’;
+——————————————————————-+
| Grants for vietnam@192.168.1.114 |
+——————————————————————-+
| GRANT USAGE ON *.* TO ‘vietnam’@’192.168.1.114’ |
| GRANT ALL PRIVILEGES ON `vietnam_xxx`.* TO ‘vietnam’@’192.168.1.114’ |
+——————————————————————-+
2 rows in set (0.00 sec)
mysql> grant all privileges on vietnam.* to ‘vietnam’@’192.168.1.114’ identified by ‘vietnam_secret_key’;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on vietnam_xxx.* to ‘vietnam’@’192.168.1.114’ identified by ‘vietnam_secret_key’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.03 sec)
mysql> show grants for ‘vietnam’@’192.168.1.114’;
+——————————————————————————————————————+
| Grants for vietnam@192.168.1.114 |
+——————————————————————————————————————+
| GRANT USAGE ON *.* TO ‘vietnam’@’192.168.1.114’ IDENTIFIED BY PASSWORD ‘*FDA32083C6301D4B9D2D49CFED881767E0XXXXXX’ |
| GRANT ALL PRIVILEGES ON `vietnam`.* TO ‘vietnam’@’192.168.1.114’ |
| GRANT ALL PRIVILEGES ON `vietnam_xxx`.* TO ‘vietnam’@’192.168.1.114’ |
+——————————————————————————————————————+
3 rows in set (0.00 sec)
[!] Thay 192.168.1.114 bằng % để đi đâu cũng vẫn mân mê được đê bê (DB)!!!
Mảng thì to mà thân em MySQL thì nhỏ!
MySQL cho phép chèn nhiều records qua một câu lệnh kiểu như sau
# Câu lệnh insert multiple:
INSERT INTO bảng VALUES (bộ giá trị thứ nhất), (bộ giá trị thứ hai), … (bộ giá trị thứ N);
Vì thế khi đẩy dữ liệu từ mảng vào database ta có thể tạo ra câu lệnh SQL như vậy, thay vì với mỗi phần tử của mảng ta lại tạo ra một bộ và INSERT INTO bảng VALUES (bộ giá trị có được);
Tuy nhiên do cấu hình max_allowed_packet, ta chỉ thực thi được câu lệnh chèn đồng thời 1 phát nhiều bản ghi với chỉ số N giới hạn.
Do đó, code phân tách mảng và generate ra các câu SQL nên làm như sau
<?php
$prefixSQL = 'INSERT INTO phimconheo(id, title, description, source, price, available) VALUES ';
$i = 0;
foreach ($data as $record) {
$id = intval($record['id']);
$title = addslashes($record['title']);
// same above for other fields
$sql .= "($id, $title, $description, $source, $price, $available),";
$i++;
if ($i == LIMIT_EXECUTABLE) {
$sql = substr($sql, 0, strlen($sql) – 1) . ";";
$sql = $prefixSQL . $sql;
echo $sql . "\n";
$i = 0;
$sql = '';
}
}
if ($sql != '') {
$sql = substr($sql, 0, strlen($sql) – 1) . ";";
$sql = $prefixSQL . $sql;
echo $sql . "\n";
}
<?php
class SoapClientTimeout extends SoapClient
{
private $timeout;
public function __setTimeout($timeout)
{
if (!is_int($timeout) && !is_null($timeout))
{
throw new Exception("Invalid timeout value");
}
$this->timeout = $timeout;
}
public function __doRequest($request, $location, $action, $version, $one_way = FALSE)
{
if (!$this->timeout)
{
// Call via parent because we require no timeout
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
}
else
{
// Call via Curl and use the timeout
$curl = curl_init($location);
curl_setopt($curl, CURLOPT_VERBOSE, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
$response = curl_exec($curl);
if (curl_errno($curl))
{
throw new Exception(curl_error($curl));
}
curl_close($curl);
}
// Return?
if (!$one_way)
{
return ($response);
}
}
}
<?php
$startTime = microtime(true);
$post_id = isset($_GET['p']) ? $_GET['p'] : 'xyz';
$memcached = new Memcache;
$memcached->connect('localhost', 11211);
if (($rows = $memcached->get('post_id_' . $post_id)) === false) {
echo 'Init cache<br />';
//yes this is safe, we type casted it already ;)
mysql_connect('localhost:3306', 'root', 'Clip2008');
$rs = mysql_query('SHOW TABLES IN mysql');
if ($rs && mysql_num_rows($rs) > 0) {
$rows = array();
while ($row = mysql_fetch_assoc($rs)) {
$rows[] = $row;
}
// cache compressed for 1 hour
$memcached->set('post_id_' . $post_id, $rows, MEMCACHE_COMPRESSED, time() + 3600);
}
} else {
echo 'Load from cache<br />';
}
var_dump($rows);
echo microtime(true) – $startTime;