Running a PHP script "seperately"?

  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Joined: Jul 28, 2003
  • Posts: 774
  • Loc: Brisbane, Australia
  • Status: Offline

Post April 15th, 2004, 11:33 pm

I don't know how to describe this, but I'll try. Here is what I am trying to acheive:

The user submits some data to a PHP script. This PHP script does some processing on this data, and then sends the results back to the user.

BUT before it finishes, it has to launch another PHP script. Now the second script has to process potentially thousands of database rows, and has to send an email for each one. This could take a few minutes, and I'm not running on a very fast server. So I want the script the user submits to to run my second script jst before the first one finished.

I hope I made sense.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 15th, 2004, 11:33 pm

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Joined: Feb 17, 2004
  • Posts: 279
  • Loc: Buenos Aires, Argentina
  • Status: Offline

Post April 16th, 2004, 11:41 am

I don't think so. May the parent script not return before the child is done, may the child die as soon as its parent script ends.

You won't be able to do that. You should think about using a contab or something.
  • ogames
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Apr 12, 2004
  • Posts: 14
  • Loc: Southampton, UK
  • Status: Offline

Post April 16th, 2004, 8:38 pm

it sounds to complex anyways! :P
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Joined: Jul 28, 2003
  • Posts: 774
  • Loc: Brisbane, Australia
  • Status: Offline

Post April 16th, 2004, 11:31 pm

_Leo_ wrote:
I don't think so. May the parent script not return before the child is done, may the child die as soon as its parent script ends.

You won't be able to do that. You should think about using a contab or something.


the trouble with that is script 1 (the one the user submits to) will need to pass some variables to script 2. How can I do this with crontab?
  • Axe
  • Genius
  • Genius
  • User avatar
  • Joined: Jan 07, 2004
  • Posts: 5744
  • Loc: Sub-level 28
  • Status: Offline

Post April 16th, 2004, 11:33 pm

Well, the second script isn't going to be able to send ANYTHING back until it's finished doing what it's doing however you call it.

It's kind of difficult to give a realistic solution to your problem with the little information we have right now. Could you elaborate some?
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Joined: Jul 28, 2003
  • Posts: 774
  • Loc: Brisbane, Australia
  • Status: Offline

Post April 16th, 2004, 11:44 pm

script 2 does not need to pass anything back.

I'll elaborate.

I am building a classified ad site. What I want is when an ad is submitted, an email will be sent out to certain people who have requested to receive an email when ads with certain keywords are posted.

But if the site is a success there mgiht be hundreds or even thousands of emails sent, and I don't want to do that from the same script that the user submits to because it will take some time and it could appear as if nothing is happening.
  • Axe
  • Genius
  • Genius
  • User avatar
  • Joined: Jan 07, 2004
  • Posts: 5744
  • Loc: Sub-level 28
  • Status: Offline

Post April 16th, 2004, 11:54 pm

Okies, you don't need to have script 1 pass anything to script 2, as long as the system you're using can run PHP files from the shell prompt.

If it can, you can run a PHP file in the cron.

Then simply have that PHP file query the database, look for the keywords they're looking for, then have it search the ads for ads containing those keywords that have been posted in the last XX minutes (since the last time the cron job had been ran).

Just do that for each user's keyword, or each user (selecting all his keywords and finding all ads that contain any of them at one time - it's doable, but don't ask me the query... my head's too tired, heh).

Script 1 can do its own thing, then when script 2 runs every 5 minutes, 10 minutes, 30 minutes, hourly, whatever... it just looks at all the ads posted since the last check and compares them to each user's keywords.

Script 2 will just happily run in the background.
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Joined: Jul 28, 2003
  • Posts: 774
  • Loc: Brisbane, Australia
  • Status: Offline

Post April 17th, 2004, 1:59 am

I never thought of doing it like that. Thanks. I'll do that.
  • Axe
  • Genius
  • Genius
  • User avatar
  • Joined: Jan 07, 2004
  • Posts: 5744
  • Loc: Sub-level 28
  • Status: Offline

Post April 17th, 2004, 2:42 am

Good luck, let us know how it goes :)

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 125 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.