user195257
user195257

Reputation: 3316

Alternative to header(location: ) php

I have a while loop that constructs a url for an SMS api.

This loop will eventually be sending hundreds of messages, thus being hundreds of urls.

How would i go about doing this?

I know you can use header(location: ) to chnage the location of the browser, but this sint going to work, as the php page needs to remain running

Hope this is clear

thankyouphp h

Upvotes: 1

Views: 2383

Answers (4)

symcbean
symcbean

Reputation: 48387

Applying a huge amount guesswork, I infer from your post that you need to dynamically create a URL, and the invoking of that URL causes an SMS message to be sent.

If this is the case, then you should not be trying to invoke the URL from the client but from server side using the url_wrappers or cURL.

You should also consider running the loop in a seperate process and reporting back to the browser using (e.g.) AJAX.

Have a google for spawning long running processes in PHP - but be warned there is a lot of bad advice on the topic published out there.

C.

Upvotes: 0

Richy B.
Richy B.

Reputation: 1617

If it just a case that during the construction of all these URLs you get the error "Maximum Execution Time Exceeded", then just add set_time_limit(10); after the URL generation to give your script an extra 10 seconds to generate the next URL.

I'm not quite sure what you are actually asking in this question - do you want the user to visit the urls (if so, can you does the end users web browser support javascript?), just be shown the urls, for the urls to be generated and stored or for the PHP script to fetch each url (and do you care about the user seeing the result) - but if you clarify the question, the community may be able to provide you with a perfect answer!

Upvotes: 0

Trevor
Trevor

Reputation: 6689

After you construct each $url, use file_get_contents($url)

Upvotes: 2

mr-sk
mr-sk

Reputation: 13427

You have a few options:

  1. file_get_contents as Trevor noted
  2. curl_ - Use the curl library of commands to make the request
  3. fsock* - Handle the connection a bit lower level, but making and managing the socket connection.

All will probably work just fine and you should pick one depending on your overall needs.

Upvotes: 3

Related Questions