ashly Posted February 27, 2007 Share Posted February 27, 2007 Hi, I have to execute multiple PHP scripts conditionally from a single PHP script, that is executed by a cron. Actually i wanted to do is instead of using require or include for each page, execute each page directly from the script like a function call. is there any methods in PHP? if anybody have any idea, pls reply.. Thanks Ashly Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/ Share on other sites More sharing options...
fert Posted February 27, 2007 Share Posted February 27, 2007 http://us2.php.net/manual/en/function.system.php Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195007 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 ok..it is nice.. thanks.. How do i use passthru() function to execute a php script? Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195041 Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 What if you just used addrees varibles to tell the php what to execute.. http://address.com/execute.php?prop1=1&prop2=1 The using requests: $prop1 = $_REQUEST('prop1') ; $prop2 = $_REQUEST('prop2') ; if ($prop1 == 1) { YOUR ECECUTE SCRIPT HERE ; } if ($prop2 == 1) { YOUR ECECUTE SCRIPT HERE ; } Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195045 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 what i am looking for is to get an example of usage of passthru() function to execute a php script from another php script.. Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195056 Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Its pretty stright forward like exec and system $command1 = "/bin/users/htdocs/test1.php" ; $command2 = "/bin/users/htdocs/test2.php" ; passthru($command1, $command2); Make sure you use the whole path or it will return error 127. Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195066 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 My code is like this: passthru("/var/www/myhost/test.php"); but it doesn't workout.. any idea? Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195084 Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 Try it without the quotes. passthru(/var/www/myhost/test.php); or user single quotes. passthru('/var/www/myhost/test.php'); Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195105 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 First one makes Parse error like: Parse error: syntax error, unexpected '/', expecting ')' in /var/www/myhost/execfunctioncaller.php on line 17 and the second one has no output... Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195106 Share on other sites More sharing options...
play_ Posted February 27, 2007 Share Posted February 27, 2007 If the second one isn't returning, does the script tell it to return a value? Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195107 Share on other sites More sharing options...
Jenk Posted February 27, 2007 Share Posted February 27, 2007 You could always try reading the manual .. http://us2.php.net/manual/en/function.passthru.php Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195113 Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 What is line 17 of the file being passed thru? Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195114 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 i read the manual completely..but no information there. As the code there is: <? print "reached here"; ?> The script test.php should have to print "reached here". Is it? Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195116 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 Line number 17 is passthru(/var/www/myhost/test.php); Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195118 Share on other sites More sharing options...
TRI0N Posted February 27, 2007 Share Posted February 27, 2007 No the error was coming from line 17 of execfunctioncaller.php... If you open test.php with that print statement it will show you nothing. Thats why you see nothing. Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195119 Share on other sites More sharing options...
ashly Posted February 27, 2007 Author Share Posted February 27, 2007 now i changed the code in test.php as mail('[email protected]', 'My Subject', 'Test message'); but i don't get the email.. the server is configured for mail fuction also.. Link to comment https://forums.phpfreaks.com/topic/40308-execute-php-scripts-like-a-function-call/#findComment-195121 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.