Same PHP code acting differently in two scripts? -


so have piece of code i'm trying download audio file running rest api in progress, it's surroundings this:

elseif($method == 'synthtts'){         //check if required parameters accounted         checkparameters($data, array('message'));         $message = $data['message'];         $message = str_replace(' ', '+', $message);         $url = "http://tts-api.com/tts.mp3?q=" . $message;         $path = "tts-mp3/" . str_replace('+', '', $message) . ".mp3";         // saveurl($url, $path);         echo $url . "\n" . $path . "\n";         $file = file_get_contents($url);         file_put_contents($path, $file);         exit("successfully synthesized tts " . $path);     } 

i pass "hello world" message parameter , echo reveals expected $path , $url values("tts-mp3/helloworld.mp3" , "http://tts-api.com/tts.mp3?q=hello+world" respectively). however, when rest 'function' no file saved. after did ran file_get_contents line , file_put_contents line in php interactive shell so.

$ php -a interactive shell  php > $file = file_get_contents("http://tts-api.com/tts.mp3?q=hello+world"); php > file_put_contents("tts-mp3/helloworld.mp3", $file); 

this worked fine. thought weird, further test, put 2 lines of code hardcoded $path , $url rest script , didn't work still. final test copy/pasted 2 lines fresh php script , ran it. worked. question "why same code act differently in 2 different scripts?"

i've tried code in php versions 5.3 , 5.4.

edit: tried moving code out of if block contains of rest functions , put @ top right below include/require statements , worked. moved down 1 line @ time until broke.

//include necessary external libraries include_once 'ses.php'; //for sending emails of aws include_once 'sns.php'; //for notification service of aws include_once 'sqs.php'; //for queueing service of aws include_once 'gearman-client.php'; //for sending jobs gearman workers include_once 'vendor/rmccue/requests/library/requests.php'; //for making web requests include_once 'twitter-api-php/twitterapiexchange.php'; //for using twitter api requests::register_autoloader();  //it works if put code here  //initialize twitter settings $settings = array(         'oauth_access_token' => "your_oauth_access_token",         'oauth_access_token_secret' => "your_oauth_access_token_secret",         'consumer_key' => "your_consumer_key",         'consumer_secret' => "your_consumer_secret"     );  //but not if put here 

i moved past definition of settings array (which haven't finished yet) , broke. weird thing when commented out $settings definition (with code still after it) still didn't work.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -