0

I am connecting to an eCommerce website's API, to get product reviews from them, what I want to do is to set the product ID which I want it's review using a loop iterator from 1 to 10, for example:

loop from i = 1 until 10
  product_id=i
// here I want to tell my php script to resubmit itself with the new product_id

I found that cron would submit it to me, but then I won't be able to loop on the product_id, I will have to synchronize between the cron and the iterator in the php script which is not efficient solution at all. does anyone know how to help me

4
  • What specific problem are you having? Right now, it seems you want the PHP script written for you Commented Jun 27, 2016 at 10:48
  • Why can't you look over product_id inside your PHP script? Commented Jun 27, 2016 at 10:49
  • I'm not exactly sure what resubmitting the script means, but cron should call the script with the loop. Commented Jun 27, 2016 at 10:50
  • of course I am now asking anyone to write my a script, u can look at baskax answer, he understood what I want correctly Commented Jun 27, 2016 at 11:12

1 Answer 1

1

You can rewrite your php script to use $argv http://php.net/manual/en/reserved.variables.argv.php

then you can pass it like

#!/bin/bash
for i in {1..5}
do
   php script.php $i
done 

save it as .sh file and add it to CRON

Sign up to request clarification or add additional context in comments.

8 Comments

thanks bro, I believe that this is exactly what I wanted, but I don't actually understand how would corn excute it ?
well you have to save this .sh file in any location, make it executable with chmod +x then add an entry to your crontab where you specify how often your script will run. You should read about crontab and its syntax or use any crontab generator that suites your needs
mmmmmmmmmmmmmmm, thanks alot bro, I will try what you have suggested
you can use an iterator in your php script directly instead of using $argv[1] variable but you still need to use cron if you want to your script run automatically every X amount of time
I have saved what you have written in a file called collectRev.sh and wrote this line inside the cron file that I am excuting from cron */1 * * * * /usr/bin/sh -o result.txt /opt/lampp/htdocs/souq-api-php-master/collectRev.sh but seems that nothing is working
|

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.