English 中文(简体)
Php中的serialize与SQLite
原标题:serialize vs SQLite in Php

I want to store arrays in file. I triend csv (fgetcsv, fputcsv) but got tons of error related with locale. I cant continue using this. I worked with serialize but editing is very hard. Also there is also a bug related .

我正在寻找一种更好的、国际化的方法来将变量存储在文件中。

SQLite可以解决。我想知道SQLite与MySQL或基本串行化相比的性能如何。如果有虫子,我也会碰到。

注意事项:

  1. Arrays are 2 dimensional arrays. Same as table->fields in DB structure.
  2. I don’t want to require additional program to install, portability is real problem, since people could install to any server, PHP, MySQL should be enough.
  3. Why I don’t want to store in MySQL, because I will use this structure to serve cache. The final product I want to publish, could run without DB, for most of the time.
  4. I wrote a basic structure using fgetcsv & fputcvs. There is bug! It strips some chars. That’s why I m looking for alternative. I don’t want to invent whole wheel from beginning but PHP guys don’t understand programming: please review: http://bugs.php.net/bug.php?id=48507
问题回答

也许您可以将数据缓存为真正的PHP。函数var_export为您提供了数据的PHP表示。它有一些限制,serialize在循环引用方面没有,但另一方面它更容易理解,因为您已经知道语法。

是否json_encode()json_decode()对您有好处?Sqlite不是多维数组的好解决方案。

您是否考虑过使用YAML,

您可以找到YAML网站此处,您可以找到一个小的lib来处理YAML此处

是的,你需要序列化它。然后你可以把它存储在任何你喜欢的地方。SQLite、MySQL、PGSQL、平面文件等。由于您正在序列化它,所以区域设置应该不会有问题。

[编辑]

当然,您应该序列化您试图存储的PHP对象。而且您不应该直接通过存储介质对其进行编辑。您应该取消对它的序列化并通过PHP对其进行操作。

[编辑]

由于您已经声明不想使用数据库服务器,因此必须使用平面文件。

我会使用SQLite。如果您不想这样做,您将需要创建自己的文件解析器。每个文件可以存储一个对象,并通过文件名识别对象。

不过,您必须考虑用户空间。如果这是一个问题,您可以使用会话。这在缓存数据时非常常见。

只是重申一下,在使用任何存储方法之前,您需要序列化数据。与SQLite相比,它不是序列化的。它是serilaize+SQLite。您需要序列化它,然后将它插入到SQLite数据库中,或者序列化数据,然后将其存储在会话中。

缓存数据并不是什么新鲜事。你没有开拓新的领域。以前已经做过很多次了。

如果您打算将数组用作列表、集合或散列,请查看键值存储redis

它的速度非常快,适合这种用途,而且有很多PHP绑定。

你的意思是do_put()方法此处?只需注意“缓存内容”部分…输出缓存文件如下所示:

<?php
$value = <<<FILEINFO_26
a:13:{s:4:"f_id";i:26;s:6:"f_hash";s:32:"d07288e848cc6219b7a793b0532f8fed";s:11:"f_extension";s:3:"jpg";s:6:"f_name";s:7:"214.jpg";s:6:"f_size";i:12902;s:10:"f_duration";N;s:6:"f_mime";s:10:"image/jpeg";s:11:"f_os_compat";N;s:9:"f_version";s:4:"NULL";s:14:"f_architecture";s:2:"32";s:7:"f_extra";N;s:11:"f_timestamp";i:1276516112;s:12:"f_dimensions";a:2:{s:5:"width";s:3:"180";s:6:"height";s:3:"227";}}
FILEINFO_26;

$is_array = 1;    

$ttl = 0; 
?> 

它使用serialize(),还可以将缓存存储在Db。。。来源此处





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签