2

I want to make a page of php that run automatically on decided time but i am confused about threads in php. Is there any possibility that a separate file run on server and check database entries without user request, like background thread.

Please Help...!

SohailRajput
  • 629
  • 1
  • 7
  • 18

3 Answers3

2

You're talking about a cron. Basically the request is done for your without user intervention. When running a cron job, PHP is (usually) run through CLI mode. Keep in mind that some super globals like $_SERVER will contain different values. But ideal for hitting the DB and doing other utility tasks.

http://articles.sitepoint.com/article/introducing-cron

JohnP
  • 49,507
  • 13
  • 108
  • 140
  • @JohnP Thanks, great article. How will we use this command to run the cron job.
    4 * * 1,2,3,4,5 wget http://www.example.com/mailstock.php
    I mean where we have to put this command...?
    – SohailRajput Mar 23 '11 at 06:15
  • 1
    If you're on a *nix system, you can type `crontab -e`. Read the `Breaking Cron Down` section on the first page. It lists the steps – JohnP Mar 23 '11 at 06:20
  • @johnP I am here confused. whether we set this command in php page or *nix command line. As i understand, we use command line, but how can we access this? – SohailRajput Mar 23 '11 at 06:27
  • 1
    You don't access it. Once you set it in the cron, as long as your server is on it will keep running the script according to the options you set in the CRON. Isn't this what you wanted? – JohnP Mar 23 '11 at 06:37
  • @JohnP Yes exactly...! I have found the path but don't know the gate to enter :) Let me study more about CRON. Thanks for your time and guid...! – SohailRajput Mar 23 '11 at 06:41
  • @JohnP I have found the gate to enter...! It is CPanel. – SohailRajput Mar 23 '11 at 07:04
  • @Sohail, yup, CPanel will do it for you. You could also do it if you have shell access. – JohnP Mar 23 '11 at 07:07
2

Multi threading is only concepts in php, but there is no implementation of multi threading in php like JAVA.

below are some good links , u must study it and u can apply your logic and need ALL D BEST

Multithreading in PHP with CURL

Easy Parallel Processing in PHP

Java concept of multi threading in PHP

stackoverflow question

Community
  • 1
  • 1
xkeshav
  • 53,360
  • 44
  • 177
  • 245
0

Since PHP is CGI based you'll have a problem running a background job. A common pattern is to schedule a CRON job that invokes some url and checks the database entries.

saintedlama
  • 6,838
  • 1
  • 28
  • 46