1

I have a PHP file (accessible on my site) that modifies rows in a MySQL database. If there are a small number of rows, the file loads quickly. However, if there are a large number of rows (over a thousand and climbing), there is a noticable pause and I would assume that this could potentially time out. Additionally, for security reasons I would prefer that the user not interface with this file directly.

I would like to make a PHP file that the user can interface with directly, but when they click ok, this page shows "Finished" immediately. However, it should connect to the first PHP file in the background and allow the rows to be modified. I don't have a lot fo experience with PHP... how should I do this? Thanks.

2
  • If you will modify these rows using single SQL query, the issue should be probably gone. Otherwise you may wish to just use some kind of queues (simple solution involves adding tasks to one table and reading them by separate script fired using cron). Commented Aug 14, 2012 at 4:50
  • @vini Wouldn't that require the client's computer to connect directly to the first PHP file? Commented Aug 14, 2012 at 4:53

2 Answers 2

2

You can do something like that:

echo "<html><h1>Finished!</h1></html>";
// now continue with your logic here
// ...
Sign up to request clarification or add additional context in comments.

12 Comments

If the user loads a different page even if the PHP file isn't done, will all of the rows still be modified?
@JackHumphries once the query starts executing - it will continue even if the user bails-out. Try it! :)
@JackHumphries when user triggered the event to send a request to the server, and then moves the page, request is still being processed on server but he won't get a feedback unless you have a way to notify them.
@GeoPhoenix according to the description he doesn't want to notify the user - just continue processing the records without making the user wait
btw, another (and a bit more complicated) option is to implement this: stackoverflow.com/a/3833095/1057429
|
0

Make the "work" PHP runnable in CLI, and in the "interface" PHP, use this:

(Windows)

<body>
<?php
pclose(popen("start /B php work.php","r"));
?>
<h1>Finished!</h1>
</body>

(Linux)

<body>
<?PHP
pclose(open("php work.php > /dev/null","r"));
?>
<h1>Finished!</h1>

If you need to pass parameters, store them in some place (e.g. database or temp file) and let the "work" PHP read them there.

You can use set_time_limit(0); in the "work" PHP to make it run without time limit.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.