0

I have two files say : 1. mail.php 2. Mail2.php

Code of mail.php goes like this :

<?
// code to send mail to stccircle@gmail.com 
sleep(20);
?>

Code of mail2.php goes like this

<?
// send another mail to stccircle@gmail.com 
?>

So, i want to execute both mail.php and mail2.php at once without sleep of mail.php affecting it.. i want to receive two mail at once..

I have tried :

require("mail.php");
require("mail2.php");

and

include("mail.php");
include("mail2.php");

Both codes wait till 20 seconds , i want the next email to be sent immediately after first one.. i want to open both link at once.

iframe fixes everything but cron job dosent support iframe.

Sleep cannot be removed because it is main part of my code.

Any solutions ? Iframe is not supported by cron jobs..

By the way, i want to run script through cron job ...

ashish.negi
  • 502
  • 3
  • 7
  • *"corn job"* - You mean CRON job. – Funk Forty Niner Jul 20 '14 at 15:55
  • Yes i mean cron job :) – StcCircle Jul 20 '14 at 15:57
  • Can't you change the php code in your mail.php? But what about gmail. Won't they complain eventually? – VMai Jul 20 '14 at 15:59
  • No, i cant change sleep on my code.. its just a demo code, i have very long code pls help – StcCircle Jul 20 '14 at 16:00
  • can you edit mail.php? you could make `sleep` conditional, like: `define("SLEEP_TIME", 0);` in the cron-mail.php and in mail.php: `if (!defined("SLEEP_TIME") { define("SLEEP_TIME", 20); }` and `sleep(SLEEP_TIME);` – pce Jul 20 '14 at 16:10
  • _“Sleep cannot be removed because it is main part of my code”_ – that makes no sense to me at all. Either you deliberately want your script to sleep for a while – then you have to live with the “consequences”, that it delays execution of code that follows it within the same script instance – or you don’t want that, which means you would have to remove it. – CBroe Jul 20 '14 at 16:13
  • Thanks for your answers :) I finally found my solution .. curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000); This worked.. – StcCircle Jul 20 '14 at 17:34

1 Answers1

0

Make two separate cron jobs instead, one that calls mail.php and the other calling mail2.php. Anohter option is making a http request to each site, but don't wait for the response. This question should help you with that.

Send HTTP request from PHP without waiting for response?

Community
  • 1
  • 1
Karl
  • 833
  • 6
  • 13