Alternative to exec in PHP?
<p>I have a PHP script that runs in the background to posts pictures to different websites. After a picture is uploaded, it will call a script to run like this:</p>

<pre><code>$user_id = "77";
exec("/usr/bin/php5 upload_auto.php?user_id=$user_id");
</code></pre>

<p>And after calling it, it runs a code like this:</p>

<pre><code>&lt;?php
$the_picture_id_to_check = $_GET['user_id'];
mysql_connect("localhost","********", "********") or die(mysql_error());
mysql_select_db(myflashp_pictures) or die (mysql_error());
require_once('connect/twitter_files/twitteroauth/twitteroauth.php');
require_once('connect/twitter_files/config.php');

?&gt;

&lt;!--- Upload Tumblr ---&gt;

&lt;?php
$result_tumblr = mysql_query("SELECT * FROM upload_tumblr WHERE user_id=$the_picture_id_to_check"); 
$num_rows_find = mysql_num_rows($result_tumblr);
while($row_tumblr=mysql_fetch_array($result_tumblr)){

// Get Username
$the_id = "".$row_tumblr['id']."";
$picture_id = "".$row_tumblr['picture_id']."";
$picture_url = "".$row_tumblr['picture_url']."";
$user_id = "".$row_tumblr['user_id']."";
$caption = "".$row_tumblr['caption']."";
$album_id = "".$row_tumblr['album_id']."";

// Authorization info
$monday_result = mysql_query("SELECT * FROM photo_albums WHERE id='$album_id'");
$monday_query_row=mysql_fetch_array($monday_result);
$tumblr_id = $monday_query_row['tumblr_id']; 

$monday_result2 = mysql_query("SELECT * FROM connections_tumblr WHERE id='$tumblr_id'");
$monday_query_row2 = mysql_fetch_array($monday_result2);
$tumblr_email = $monday_query_row2['email']; 
$tumblr_password = $monday_query_row2['password']; 

// Prepare POST request
$request_data = http_build_query(
array(
    'email'             =&gt; $tumblr_email,
    'password'          =&gt; $tumblr_password,
    'type'              =&gt; 'photo',
    'source'            =&gt; $picture_url,
    'caption'           =&gt; $caption,
    'generator'         =&gt; 'FlashPics iPhone App'
)
);

// Send the POST request (with cURL)
$c = curl_init('http://www.tumblr.com/api/write');
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $request_data);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($c);
$status = curl_getinfo($c, CURLINFO_HTTP_CODE);
curl_close($c);

// Check for success
if ($status == 201) {
mysql_query("UPDATE pictures SET tumblr_id='$result' WHERE id='$picture_id'");
echo "Success! The new Tumblr post ID is $result.&lt;br&gt;\n";
mysql_query("DELETE FROM upload_tumblr WHERE id='$the_id'");
} else if ($status == 403) {
echo 'Bad email or password for Tumblr.';
} else if ($status == 400) {
echo "Error ($status): $result\n";
mysql_query("DELETE FROM upload_tumblr WHERE id='$the_id'");
} else {
echo "Error ($status): $result\n";
}

}

if ($num_rows_find == 0) {
echo "There's nothing to post to Tumblr.";
}

?&gt;

&lt;br /&gt;&lt;br /&gt;



&lt;!--- Upload Email ---&gt;

&lt;?php

include_once('class.phpmailer.php');

$result_email = mysql_query("SELECT * FROM upload_email WHERE status='processing' AND user_id='$the_picture_id_to_check'"); 
$num_rows_find = mysql_num_rows($result_email);
mysql_query("UPDATE upload_email SET status='$num_rows_find' WHERE id='1'");
while($row_email=mysql_fetch_array($result_email)){

// Get Username
$to = "".$row_email['email']."";


$get_info_result = mysql_query("SELECT * FROM users WHERE id='".$row_email['user_id']."'");
$get_info_query_row = mysql_fetch_array($get_info_result);
$get_username = $get_info_query_row['username'];
$get_first_name = $get_info_query_row['first_name'];
$get_last_name = $get_info_query_row['last_name']; 

$get_info_result = mysql_query("SELECT * FROM pictures WHERE id='".$row_email['picture_id']."'");
$get_info_query_row = mysql_fetch_array($get_info_result);
$get_caption = $get_info_query_row['caption'];
$get_picture_url = $get_info_query_row['long_url'];
$get_short_string = $get_info_query_row['short_string'];

if ($get_caption == "") {
$get_caption = "I have shared a FlashPic with you.";
}


$mail             = new PHPMailer();
$mail-&gt;From       = "share@myflashpics.com";
$mail-&gt;FromName   = "FlashPics";
$mail-&gt;Subject    = "$get_first_name $get_last_name has shared a FlashPic with you.";

$mail-&gt;IsHTML(true);
$mail-&gt;Body = "
&lt;html&gt;&lt;body style='margin: 0px; padding: 0px;'&gt;
&lt;div style='padding: 15px; width: 480px; font-family: Helvetica; margin: 10px; border: 1px solid #d7d7d7;'&gt;
&lt;div style='font-weight: bolder; font-size: 32px; margin: 8px 0px 20px 0px;'&gt;&lt;font color='#353535'&gt;Flash&lt;/font&gt;&lt;font color='#f8bc49'&gt;Pics&lt;/font&gt;&lt;/div&gt;

&lt;div style='font-size: 20px; color: #353535; font-weight: normal; text-transform: lowercase;'&gt;$get_username&lt;/div&gt;

&lt;div style='margin-top: 15px; font-size: 14px; line-height: 18px;'&gt;$get_caption&lt;br&gt;
&lt;br&gt;
&lt;img src=$get_picture_url width='480'&gt;
&lt;br&gt;&lt;br&gt;
&lt;a href='http://myflashpics.com/picture/$get_short_string' style='color: #000000; text-decoration: underline;'&gt;view full size image&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Sincerely,&lt;br&gt;
The FlashPics Team&lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;&lt;/html&gt;";

$mail-&gt;AltBody    = "$get_username
$get_caption

http://myflashpics.com/picture/".$row_email['picture_id']."

Yours Truly,
The FlashPics Team";


$the_id = "".$row_email['id']."";

$pieces = explode(", ", "$to");

$one = $pieces['0'];
$two = $pieces['1']; 
$three = $pieces['2']; 
$four = $pieces['3']; 
$five = $pieces['4']; 

if ($one != "") {
$mail-&gt;AddBCC("$one");
}
if ($two != "") {
$mail-&gt;AddBCC("$two");
}
if ($three != "") {
$mail-&gt;AddBCC("$three");
}
if ($four != "") {
$mail-&gt;AddBCC("$four");
}
if ($five != "") {
$mail-&gt;AddBCC("$five");
}

if(!$mail-&gt;Send()) {
echo "Failed sending email to &lt;b&gt; $one, $two, $three, $four, $five&lt;/b&gt;." . $mail-&gt;ErrorInfo;
mysql_query("UPDATE upload_email SET status='error' WHERE id='$the_id'");
} else {
echo "Sent email to &lt;b&gt; ".$row_email['email']."&lt;/b&gt; successfully.&lt;br&gt;";
mysql_query("UPDATE upload_email SET status='sent' WHERE id='$the_id'");
}

}

if ($num_rows_find == 0) {
echo "There are no pictures to email out.";
}

?&gt;
</code></pre>

<p>So basically only certain parts will work (I didn't post all my code). I just posted what wasn't working. <strong>But if I run it manually from the browser, all parts working</strong>. If you want to see my php_info, I have it <a href="http://myflashpics.com/info.php" rel="nofollow">here</a>.</p>

<p>Thanks in advance,<br>
Coulton</p>

<p><em>PS: By "Not Working", I mean that nothing happens and I see no errors</em></p>
