What exactly is caching? [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 7 years ago.
Improve this question
Someone asked me to cache the XML call im pulling in to prevent server trouble. But now my question is, what exactly is caching, and how do i do it?
Hope to find some answers here.
Is it a way to save the XML output to a file, and then use that file? But how do i check if there are any updates than, or when somebody closes the browser? Or do i store the XML in a SESSION or COOKIE?

Caching is the action to remember your calls during a limited time in order to prevent unnecessary calls.
For exemple, it can be like this :
You check if there is something already cached.
There is nothing, so you make your call.
You save the answer of your call for a limited time.
Next time you will check the cache, you won't call, but just user the saved answer.
You can be inspired by this script : http://www.finalwebsites.com/snippets.php?id=49

Related

Run script when session starts? [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
How do I run a script (ie, $viewcount += 1;) when a session starts in PHP? I'm trying to make a view counter script for my website which currently works, assuming I include('view_counter.php') in every page to add something to my text file of views. Unfortunately, people can reload the page and so add up the view count really quickly. What I'd like to do is add to the view count every time somebody opens a new session on the site. It should be obvious, but how do I do it?
Just check if the Session object exists or not yet using an IF statement, and if it doesn't, it means it's a new session in which you can run your counter code.
More info on working with sessions: Check whether a session is new in PHP

How I can find where page can't end to load? [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 have a page that doesn't end to load. PHP max_execution_time is set to 30 but the icon in the Chrome tab doesn't end to turn. What tool I can use to find where the script is?
PHP log are clean, and this is a simple login page made using laravel.
I discover that problm are caused by cookie, in fact if I load page using Chrome hidden mode I have not the problem.
PHP max execution time is for PHP. There are several other things that have to process as well, like MySQL. The time it takes SQL to do stuff is not included in the PHP max execuion time. Beyond that, you'd have to show some code to figure out why.
To anwser your question, the browser is a pretty good tool for that. Or if a rewrite is hiding the filename you could grep for a unige string from the source, assuming you know which parts are PHP generated.

Is it better to store configuration in a file or database? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm currently working on a project that uses MySQL for configuration, but now I'm starting to think it could slow down page loads.
So my question is, would it be better to store configuration options (that are read almost every page load) inside an XML/JSON file, or a MySQL database?
Thanks.
One thing to conside is how much config data there is, and perhaps how often it is likely to change. If the amount of data is small, then saving this in a database (if your not already using a db for anything else), would be overkill, equally maintaining a db for something that gets changed once every 6 months would probably be a waste of resources.
I think this depends on your projects. If you want someone else to configure the application through the UI you can put the configurations into the database.
If its just you and some developers, and changes are not made frequently, put them in a file.

get cookie of other website on my webpage [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 9 years ago.
Improve this question
I am trying to get the facebook cookie on my webpage, but I am being unabe to do this.
I tried this but it returned null.
Please give me the php script if you know.
You are trying to do the impossible.
You just can't read other websites cookies, you may just could read their headers though.
You could grab their headers like this.
<?php
file_get_contents('https://www.facebook.com');
var_dump($http_response_header);
That would be a huge security issue on both Facebook's end and the browser's end.
You should never be able to do that ever for any reason ever.

Php get variable params at each modification not from script [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
How does it possible to get variable modificated values, after script ended? im going to make a small and very simple caching system, for start to cache just needs to put "cache" commented where need to start cache and same when ends, only problem is to emulate all script and, as i said, get each changed instance of var.
Usually there is more simpler, just integrate the caching in your script, the process would be
verify there is some cache and it's not expired
if there is some not expired cache use it, end
render the page and capture it using ob_* functions
build the cache
This way you don't have to emulate anything, just to wait that some people visit the page, plus you don't built cache for page that are never visited.

Categories