PHP script run once, even on two machines [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 2 years ago.
Improve this question
I have a PHP script basic update script, i want it to run only once, it is running once on a single machine, but when i use two machines and run it at the same time, pressing the buttons at the same time it is running twice, how to solve this?

There's not really enough info here to answer the question definitively, but I'll take a stab at it.
First, my assumptions. You have a web server with a PHP application that shows a web page with a button on it. You load the page on two different computers (or in two different browser windows). When you click the button in one browser, you want to prevent it from running when you click it in the other browser.
You need some flag on the server that:
gets set the first time the button is clicked and your update process is started
is checked the second time the button is clicked (and prevents your update process from running again)
gets unset when the update process finishes.
There are many ways to do this. The simplest if probably creating a file in the filesystem when the button is clicked the first time. More complicated ways of doing this include setting a value in a database or a key value store like Redis.
Edit Highlighted "on the server" because, from the comments above, it sounds like the OP is setting a flag in an HTML element.

Related

Sending email using php mail function - Getting slow [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 5 years ago.
Improve this question
I have set up a php function to send email when a button is clicked using isset($_POST['id']).
I am receiving the mail correctly but its takes approximately 8 sec to navigate to the next page.
I know it will take a bit of time to login into mail server and sending the mail.
Is there any way to avoid the latency, e.g. by doing it as a background process?
when button is clicked that time you can call the AJAX, you can set the loader on the page when mail sent that time you can hide the that loader
Well, if it is a background process, you can do it with ajax call.
Ajax is the first answer, but if you want it to be called by server you can just exec('php your_php_code_sending_mail.php param1 param2') ; so the user not even have to load the result page in browser, so you can make your validations in PHP and are not dependant on the user browser. You just need some specific rights, depending on your server configuration.

Keep track of user selected elements even after they leave the page [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 7 years ago.
Improve this question
I am making an enrollment system in which users can select courses that they wish to take. It is a multi-page website where users first select a topic then they are directed to a new page where a list of courses associated with that topic is loaded from a MySQL database. When the user finds a course they want they click on a button and the course is added to a session variable with an AJAX call. I want to add an image or text that lets the user know that they added that course once they do. Currently there is no way the user can tell if they added the course or not. This of course is easily done when the user first adds the course. I can have a hidden image that is toggled on click. This however will be forgotten on page reload.
The question is, how can I flag the course(s) they added if they reload the page or leave that topic's page and later come back to it?
A possible solution that I came up with was to upon every page load to search the list of courses that are in the session variable for matches on that current page, then set the "Added" image to visible using jQuery. Is this a good solution? Is there a better one? I hope this is not too open-ended.
yes you can do it as you described on your own (the jQuery way)
maybe a:visited could do the job for you (i don't think so but you never know before trying)
regards :)

How do you insert a new user every minute using a mySQL database? [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 7 years ago.
Improve this question
I am wondering if there is a way to add a new user automatically in a mysql table every minute or so ?
I have a USER table and a USER ACTIVE table, when ever a user is active the details goes under the USER ACTIVE table. I would like to automatically be able to add and delete x number of users from the USER ACTIVE table every minute.
How do I achieve this? I am also a beginner with PHP (which is what I am using) MySQL.
You can't do what you want in pure PHP. PHP is designed to render a page on request and then finish, it won't keep running with a timer. You can either set up a cron job as Dagon suggests, or look at adding some java or similar that keeps running a timer once the page is loaded - which I don't think you want, because that would still require the page to be open somewhere.
I have something similar set up using only PHP, the cron job simply launches the PHP interpreter to run the page every so often: "php /home/user/timer.php". Exactly how you set this up is going to depend on what level of access you have to the system and what commands are available, but most web hosts will allow the setup of a basic cron job.

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.

How to determine what part of an AJAX application is slowing things down? [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'm writing my first AJAX driven website and some parts of it are kind of slow. For example, I'll click a button to change the page, and it might take three seconds for the new page to appear.
Chrome developer tools shows the network activity for the page being changed as follows:
DNS Lookup ​1 ms
Connecting ​45 ms
SSL ​21 ms
Sending ​0
Waiting ​1.89 s
Receiving ​73 ms
The size of the above request was 49.1 KB.
Clearly the "Waiting" time is where the slowdown is occurring. My question is, what is causing this "waiting" time? Is it something to do with the jQuery AJAX request, or is it because the MySQL database is slow, or something in a PHP file causing a delay?
Without seeing my project and debugging it first-hand, you may not be able to answer that question. If that's the case, how should I go about determining which part of the application is slowing things down?
Without seeing my project and debugging it first-hand, you may not be able to answer that question. If that's the case, how should I go about determining which part of the application is slowing things down?
That depends on your debug tools. At the most basic level, comment out parts of your server-side code and check how much the "waiting" time drops.
I don't know anything about profiling MySQL/PHP applications (in Django, you could use django-debug-toolbar), but Ajax queries are good candidates to cache in both DB and app output layers.
Consider using a cache system like memcached.

Categories