PHP variable for all users on server [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
It is possible to define variable in PHP and call it for all users connected on server?
I need variable, or object for store informations in RAM of the server without using database or server file system.
Save the data to the variable in one computer, and call them back in another connected computer.
What is the best practice, is it possible?

Roughly - yes, it is possible.
In order to do that you need to have access to RAM which I haven't seen in PHP done directly, not sure if is possible or not, you can research this yourself.
What you can do is, however, since PHP uses memory to run, you can take advantage of that and create a php script that will run forever and act as a server, that is going to use it's ability to write and read memory and is going to be an amazingly simple job since PHP handles that for you automatically and you would not have to bother with addresses and stuff ( describing a simple variable declaration ). In order to access this running script you will need to examine how sockets work and how to establish a server-client connection. That is very well explained in this article.
However, I do not mean to be rude, but by the way you form your question I can make an assumption that this may be too much for you, so I guess what you can do is use MemcacheD or any other in-memory caching mechanism that is already built by people better at coding than me and you. There is plenty of information out there, just search for in-memory caching mechanisms.
Good luck!

Related

Which one is faster in codeigniter reading value from Session or Pursing value from URL parameter? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
In my web app I have to show content depending on user location. As it is not possible to resolve current location in every request I can set it on URL parameter or Store it on session for further requests. But I am getting confused about which one will be faster? Pursing the location from url parameter? or reading the location from session in every request?
Getting an information from the URL itself will probably always be faster than sessions since it's available right away in the memory. How faster is it will depend on the storage method of your sessions. Sessions stored in an external database may take a few milliseconds to load, for example.
Testing it locally sequentially will probably yeld the same results for both methods. To get a reliable benchmark you'll need to test it concurrently with hundreds or thousands of requests per second.
Either way, you shouldn't worry about that kind of optimization, just choose the solution that will be easier to maintain. The URL has the added benefit of being scalable and stateless.

Storing ONE global value in php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to store one global decimal value.
Would the best way to approach this be to store the value in a .txt file, or make an entire table for it in MySQL which will contain a single row for the value, or is there a different way?
It deppends on how often you will access it and how performance critical your application is. In brief DataBase should be your default unless you have a strong reason not to.
The reasons to keep the data in the database it's because it makes everything simplier and neater, backups don't need to worry about random .txt files that may be overlooked (And this a incomplete backup). If you need to set up a cluster it's a real PITA to keep files real-time synched while most databases support it easily, etc.
Why wouldn't you keep something in the database?
It's a enviroment value and thus in each installation of your
software the value may be different while using the same DB (In this
case people use File storage like the usual config .yml)
It's really performance critical to
have a top notch access-time to this data, for this people use
specialized engines to store such data (Redis, memcached, etc)
Now, answering your question, how to store it in your own db, that's up to you, but I would think something like a table named "GlobalConfigurations" with a column key and value could be a good approach. So that if you find any other variable with the same behavior you can put it there.

SQL threads from many sub domains or sub folders on website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a script that I wrote for Online games payments, now the thing is the people who's going to use it , will use it on my host on a sub folder ( payments.example.com/name/ )
I haven't figure out how to build an instance API in order to make whole script work from one directory ( using $_GET ) for system to recognize who they want to pay to seems a little wrong, or maybe i'm just over stressed I don't know, you can suggest me a solution if you can.
Now my question is , since the host will have, for example, 20 different project using the same script copy ( just with different sql settings ) and all of them will send an info to their databases, Plus all that copies will send info to main database in my host already ( for logs and statistics in their admin panel )
Will that cause any problems? Is there anything you can suggest for better performance and usage?
Depends on your livesystem and database Server Quality. If its a good one it shouldn't have problems with doing that. I think you just need to start your Service and Monitor the Server Memory and CPU Usage.
If you already want to see wether or not you have some narrow pieces in your code, your probably want to use a PHP Profiler to profile your Code on your production server.
See http://www.xdebug.org/ as example tool. But you need to deactivate it bevor Publishing the Service on your live System
And you should think about the Copys in youre main Database. Thats just additional non nessesary traffic between PHP and you Database.
Hope I helped you

PHP and SQL basic instant messaging [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am thinking of creating a simple web based instant messaging using a combination of PHP and SQL. To keep it simple I was thinking of not sending the message to the other clients browser using COMET or AJAX, but simply uploading it to a SQL database. The other clients computer will then periodically refresh the webpage which will cause the PHP code on the server to check for and return any new messages.
Would this method be simply to slow to be actually useful?
Thanks in advance :)
That depends on the scope of your project. If you're thinking of server a thousand users, this is not a recommended method. If you want to chat with your 5 colleagues on an internal LAN: it doesn't really matter much. It will be fast and work just fine.
You could also consider building it with jQuery + PHP + SQL though; read up on jQuery a bit and you'll be amazed by the power of its AJAX functions.
Also, if you're lazy or simple don't have enough time, use a premade library like this one here and i'm sure there are many more to be found on the internet.

virtual pages using PHP only? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am working on a project that I need to let users to create pages on my server. however, I do not want to let users clutter my mysql database by storing the stuff in there so I cannot use mysql database for creating the pages.
I did research this topic and there seem to be a some sort of a plugin for WP that will allow virtual page creation.
is this possible using pure php WITHOUT the use of any database ?
It's possible, but wrong.
You can use php to write a html file to your web directory, sure. But that
solution is in no way cleaner or less cluttered than putting stuff in your
database, for a few reasons:
It's easier to have structured information in the database
It's a good thing conceptually to separate user data from your program
It's easier to control access to your database in a safe way, compared
to writing user data to the file system
"I really do not want to use mysql database" is not a good reason to give this
up. You might have a good reason, but it's not easy to guess what that is, which
makes suggesting alternatives very difficult.

Categories