dongpao1873 2010-11-15 09:25
浏览 24
已采纳

如何在php中应用静态类

I am java and php programmer. In java i can use static class/method so that anyone can use the same one time created class during run-time.

But for php how to do it since it is script based and only run while we refreshing the page?

My main objective is, I want to use syncronized class/method so that it wont clash while executing the PHP...

Need your help to give input. Thanks

Update:

  1. I am doing portal like multi level marketing(mlm)
  2. Once register a member, we should pay bonus to the uplines
  3. I don't want immidiately calculate the bonus because it is risky and could take some time to finish, so is is better just to register the member and show successfull.
  4. My idea is, after registration, just invoke another class to run bonus with syncronized method so that the bonus calculation will not disturb by another registration.
  • 写回答

2条回答 默认 最新

  • duana1021 2010-11-15 10:04
    关注

    Given that a php scripts runs from new every sinlge time a "static" class would not be very different from an ordinary class.

    If you want to store some sort of state or preserve some data between runs of a php program then there are a number of options.

    SESSION variables can be used to store data between requests from a single users as long as he keeps the session open.

    COOKIES can be used to store data which persists between sessions as long as the user is using the same browser, on hte same machine and hasnt emptied the cookie jar.

    memchached and similar packages can be used to store data and make it available to any php program on the server.

    Databases are the most scalable solution as they will persist data between sessions, and between servers. There is some overhead involved is establishing connections and retrieving the data compared with the other solutions.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址