Running a PHP script "seperately"?

  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

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
  • ogames
  • Posts: 14
  • Loc: Southampton, UK

Post 3+ Months Ago

it sounds to complex anyways! :P
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

_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
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

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
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

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
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

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
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

I never thought of doing it like that. Thanks. I'll do that.
  • Axe
  • Genius
  • Genius
  • User avatar
  • Posts: 5739
  • Loc: Sub-level 28

Post 3+ Months Ago

Good luck, let us know how it goes :)

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: Bogey and 93 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.