| | |
Running PHP scripts in backround
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2004
Posts: 39
Reputation:
Solved Threads: 0
Hi there,
I am wondering does anyone have any idea how to execute PHP scripts (a maintenance script in my case) in the background. The reason for this is because I don't want visitors to be slowed down by the maintenance execution, so having it run as a separate process would help a lot.
I have thought about running cron jobs but I want to enforce a maintenance if cron job stops working for some reason.
Any help or ideas would be greatly appreciated.
tim
I am wondering does anyone have any idea how to execute PHP scripts (a maintenance script in my case) in the background. The reason for this is because I don't want visitors to be slowed down by the maintenance execution, so having it run as a separate process would help a lot.
I have thought about running cron jobs but I want to enforce a maintenance if cron job stops working for some reason.
Any help or ideas would be greatly appreciated.
tim
PHP script always executed at the background, if not mistaken.
I run my maintenance routine everytime I log in to my admin area. It will not affect my clients' site and yet keep my database clean. I log in at least once a week and did not notice any delay or slow down. I think you can do the same.
I run my maintenance routine everytime I log in to my admin area. It will not affect my clients' site and yet keep my database clean. I log in at least once a week and did not notice any delay or slow down. I think you can do the same.
Ecommerce-Web-Store.com Building Your e-Business.
•
•
•
•
Originally Posted by timhysniu
Thanks guys![]()
I was just hoping of an idea to run a php script initiated by a visitor where a user wouldnt have to wait for the whole maintenance execution. I guess kind of like branching a single process into two. Thats something I havent done before; Im not sure if its possible.
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
•
•
Originally Posted by timhysniu
Thanks guys![]()
I was just hoping of an idea to run a php script initiated by a visitor where a user wouldnt have to wait for the whole maintenance execution. I guess kind of like branching a single process into two. Thats something I havent done before; Im not sure if its possible.
What you could do is use the exec() function in PHP that always to to execute shell commands. (Also see: popen, and proc_open() )
You can use the & option to run the command in the background.
Example:
[PHP]
<?php
exec( 'wget http://www.example.com/file.php > /dev/null &' );
?>
[/PHP]
The > /dev/null sends your php output to nowhere.
The & makes the wget run in the background.
You can use other commands rather than wget, but thats one Im sure of the syntax for.
If you cant use exec() then you could try using the HTTP protocol to your advantage to fork your php script for you.
I havent tested but I believe if you could do something like:
[PHP]
header( 'Location : http://www.example.com/new_file.php' );
echo str_pad(' ', 256); // make IE start rendering
flush();
// Do your other stuff here, in the background
// The browser is now fetching http://www.example.com/new_file.php
// Make sure you dont output anything
run_my_maintanence();
[/PHP]
I believe this will work.
For IE to actually start following the HTTP headers, it has to receive at least 256 bytes of content.. (now why?)
See if either of those work for you.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
PHP does always run in the background it is server side scripting. something like javascript which is client side would run in the foreground.
I've posted an entry about this in my blog. if you are interested check out:
http://fijiwebdesign.com/content/view/86/77/
http://fijiwebdesign.com/content/view/86/77/
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Other Threads in the PHP Forum
- Previous Thread: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
- Next Thread: Paasing the values of Combo Box
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql navigation number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white xml youtube







