将数组保存在内存中 [英] Keeping an Array in Memory

查看:104
本文介绍了将数组保存在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我害怕我不太了解PHP

来解决这个问题。


我想要保持一个数组在

内存中,因此每次运行.php脚本时都不需要重新加载$ ​​b $ b。


这可能吗?


在Java中,我可以在servlet的init()方法中从文件

加载数组,它会

留在内存中直到服务器关闭

或重新启动等等。


谢谢,


Andrew

解决方案

安德鲁,


你是什么意思重新载入?


无论如何......你可以使用会话或简单的cookie。阅读一些教程

(google)php中的会话以及它们如何工作如果你还不知道

还没(我会猜)并且看看php会议手册

功能。


祝你好运;),


克里斯托弗


Andrew schrieb am 18.06.2004 02:36:

我害怕我不太了解PHP
想出这个。

我想要的是将数组保存在内存中,以便每次运行.php脚本时都不必重新加载。

这可能吗?

在Java中,我可以从servlet的init()方法中的文件加载数组,它会保留在内存中直到服务器关闭
或重新启动等等。

谢谢,

Andrew



Andrew写道:

我害怕我不太了解PHP
到f this这个。

我想要的是将数组保存在内存中,以便每次运行.php脚本时都不必重新加载它这可能吗?

在Java中,我可以从servlet的init()方法中的文件加载数组,它会
留在内存中,直到服务器关闭
或重新启动等等。

谢谢,

Andrew




Andrew,

与Java servlet环境不同,PHP中的数组不会保存在
内存中。您的脚本创建的所有对象将在执行

结束时销毁。因此,一旦您的脚本完成加载页面,存储在内存中的所有数据都将标记为垃圾回收。您将不得不将数据结构(我假设您想要保存持久的

数据)存储在数据库,平面文件或任何其他位置。

喜欢。


Amir。


-

规则是为那些缺乏真正推理能力的人,但对于那些能够做到的人来说,这些规则只不过是指导方针,并且生活在他们的生活中,而不是由规则而是由理性支配。

- James McGuigan


Andrew,

与Java servlet不同环境,PHP中的数组不保存在内存中。您的脚本创建的所有对象将在执行结束时销毁。因此,一旦您的脚本完成加载页面,存储在内存中的所有数据都会被标记为垃圾回收。您必须将数据结构(我假设您想要保存持久的数据)存储在数据库,平面文件或您喜欢的任何其他位置。

Amir。




是的,我正在使用平面文件。


我正在加载每次运行脚本时都会这样。


这对性能似乎不好,因为它是

与加载完全相同的数组。


有没有办法解决这个问题?


Andrew


I''m afraid I don''t know PHP well enough
to figure this out.

What I would like is to keep an array in
memory so that it doesn''t have to be
reloaded each time a .php script is run.

Is this possible?

In Java, I could load the array from a file
in the init() method of a servlet and it would
stay in memory until the server is shutdown
or restarted, etc.

Thanks,

Andrew

解决方案

Hi Andrew,

what do you mean "reloaded"?

Anyways... you can use sessions or simple cookies. read some tutorials
(google) what sessions in php are and how they work if you don''t know
yet (as i would guess) and look into the php manual for the session
functions.

Good Luck ;) ,

Christopher

Andrew schrieb am 18.06.2004 02:36:

I''m afraid I don''t know PHP well enough
to figure this out.

What I would like is to keep an array in
memory so that it doesn''t have to be
reloaded each time a .php script is run.

Is this possible?

In Java, I could load the array from a file
in the init() method of a servlet and it would
stay in memory until the server is shutdown
or restarted, etc.

Thanks,

Andrew



Andrew wrote:

I''m afraid I don''t know PHP well enough
to figure this out.

What I would like is to keep an array in
memory so that it doesn''t have to be
reloaded each time a .php script is run.

Is this possible?

In Java, I could load the array from a file
in the init() method of a servlet and it would
stay in memory until the server is shutdown
or restarted, etc.

Thanks,

Andrew



Andrew,

Unlike in a Java servlet environment, arrays in PHP are not kept in
memory. All objects created by your script are destroyed at the end of
execution. So, once your script is done loading the page, all data
stored in memory is marked for garbage collection. You will have to
store your data structures (I am assuming you want to save persistent
data) in a database, flat file, or any other location that is to your
liking.

Amir.

--
Rules are written for those who lack the ability to truly reason, But for
those who can, the rules become nothing more than guidelines, And live
their lives governed not by rules but by reason.
- James McGuigan


Andrew,

Unlike in a Java servlet environment, arrays in PHP are not kept in
memory. All objects created by your script are destroyed at the end of
execution. So, once your script is done loading the page, all data
stored in memory is marked for garbage collection. You will have to
store your data structures (I am assuming you want to save persistent
data) in a database, flat file, or any other location that is to your
liking.

Amir.



Yes, I''m using a flat file.

I am loading this everytime the script it run.

This does not seem good for performance since it''s the
exact same array that gets loaded.

Is there no way around this?

Andrew


这篇关于将数组保存在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆