我正在寻找一种非常快速的方法来读取csv文件.我的数据结构如下所示:
timestamp ,float , string ,ip ,string
1318190061,1640851625, lore ipsum,84.169.42.48,appname
Run Code Online (Sandbox Code Playgroud)
我正在使用fgetcsv将这些数据读入数组.
问题:表现.脚本必须定期读取(和处理)超过10,000个条目.
我的第一次尝试非常简单:
//Performance: 0,141 seconds / 13.5 MB
while(!feof($statisticsfile))
{
$temp = fgetcsv($statisticsfile);
$timestamp[] = $temp[0];
$value[] = $temp[1];
$text[] = $temp[2];
$ip[] = $temp[3];
$app[] = $temp[4];
}
Run Code Online (Sandbox Code Playgroud)
我的第二次尝试:
//Performance: 0,125 seconds / 10.8 MB
while (($userinfo = fgetcsv($statisticsfile)) !== FALSE) {
list ($timestamp[], $value[], $text, $ip, $app) = $userinfo;
}
Run Code Online (Sandbox Code Playgroud)
谢谢 :)
我想在数据库中的密码旁边存储一个(随机)盐。现在,问题是:
我应该将其存储为散列还是纯文本?有什么区别吗(更安全、更快?)?我应该花多少精力来创建随机字符串?
示例代码:
//Creating random salt
$saltchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./:;<=>?@[]^_`{|}~";
$salt = uniqid(rand(), true).str_shuffle($saltchars);
// Or should the salt be hashed (md5 or sha512 for more security)
// $salt = hash('sha512', uniqid(rand(), true).$staticsalt.str_shuffle($saltchars));
//Create user (with salt & pepper)
$sqlquery = "INSERT INTO users (user, password, salt) VALUES('$id','".hash('sha512', $staticsalt.$accesskey.$salt)."','".$salt."');";
$sqlresult = mysql_query($sqlquery);
Run Code Online (Sandbox Code Playgroud)
记录一下:登录脚本
$sqlquery = "SELECT salt FROM users WHERE user='$id';";
$sqlresult = mysql_query($sqlquery);
if (mysql_num_rows($sqlresult) == 1) {
$salt = (mysql_fetch_array($sqlresult));
//Check if the password is correct
$sqlquery = "SELECT …Run Code Online (Sandbox Code Playgroud)