Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Tuesday 6 February 2018

php is not recognized as an internal or external command wamp

Question: How to "Fix php is not recognized as an internal or external command wamp"?

Step 1
Click on Start Button => Right Click on Computer => Click on Properties

Window 7 go to the properties


Step 2
An Popup will appear => Click on "Advance System Setting" (Left Panel)


Step 3
Click on "Environment Variable"

Window 7 go to the System properties


Step 3
A popup will appear, Select PATH and click on "EDIT"
Window 7 Edit Environment Varaible



Step 4 Add you php.exe path at the end of input box like below:
;D:\wamp\bin\php\php5.5.12\

Window 7 Set php.exe path in environment variable


Friday 6 October 2017

How to install ffmpeg in wamp server in Windows7

How to install ffmpeg in wamp server in Windows

Question: What are Simple steps to install ffmpeg in wamp server in Windows?
  1. Download FFmpeg for Windows
    https://ffmpeg.zeranoe.com/builds/
  2. Extract the downloaded Zip file.
  3. Copy bin/ffmpeg.exe, bin/ffplay.exe and bin/ffprobe.exe from downloaded and paste in C:\Windows\System32
  4. Create a folder with name ffmpegtest in path d:/wamp/www (Drive can be different as per wamp installation)
  5. Login to Command prompt and go to d:/wamp/www/ffmpegtest using cd command
  6. Execute following command (To download composer)
    php -r "readfile('https://getcomposer.org/installer');" | php
    

    It will download the composer.phar
  7. Execute following command to download PHP-FFMPEG library.
    php composer.phar require php-ffmpeg/php-ffmpeg
    
  8. Test the FFMPEG with php
    include "vendor/autoload.php";
    $ffmpeg = FFMpeg\FFMpeg::create();
    print_r($ffmpeg);
    
    When it print the object, means FFMPEG setup successfully.


Question: What can we do with ffmpeg?
-Cut the video
-Combine two or more videos into one
-Extract the one video portion from main video
-Resize the video
-Extract the audio from video
-Combine photo+audio into video
-Change the sample rate
-Watermarking on vi



Question: What is Bitrate?
Bitrate describes the rate at which bits are transferred in ffmpeg. Bitrate is commonly measured in bits per second (bps),kilobits per second (Kbps), or megabits per second (Mbps).


Question: What is Frame Rate?
the frame rate is the number of frames or images that are projected or displayed per second.


Question: What is demux?
A demux(er) is a module responsible for extracting the contents of a given file/stream format, for instance AVI, OGG, MPEG2, WAV, etc.


Question: How to convert .wav to .mp3?
include "vendor/autoload.php";
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open( 'audiofile.wav' );
$audio_format = new FFMpeg\Format\Audio\Mp3();
// Extract the audio into a new file as mp3 and save in folder
$video->save($audio_format, 'audiofile.mp3');



Question: How to transcode a wav to flac?
include "vendor/autoload.php";
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open( 'audiofile.wav' );
$audio_format = new FFMpeg\Format\Audio\Mp3();
$video->save($audio_format, 'audiofile.mp3');


Tuesday 3 October 2017

How to create built in web server in PHP?

How to create built in web server in PHP

Question: In which PHP Version Built-in web server come?
PHP 5.4


Question: Can we run php without apache?
Yes, We can run the php independent.


Question: Can we test our application with Built-in web server feature?
Yes, We can.


Question: Can we test our application with Built-in web server feature?
Yes, We can use this feature to test our module.


Question: Can we go LIVE with Built-in web server ?
Not, Its recommended We should not go LIVE with this Built-In Web Server.


Question: How to check If built-in Web server is available in your PHP Build?
Way 1
print the phpinfo() in php. and Search for Built-in HTTP server , If found means It is available.

Way 2
in php command line, execute following command

php -h

Search -S (Run with built-in Web server), If found means It is available.


Question: How to run PHP Script with built-in Web Server?
Go to file Location and execute following command from command line.
php -S 0.0.0.0:8080 myfile.php



Question: What is use of -S?
It is used to specify the Ip Address with port with which bind.


Question: What is use of -t?

It is used to specify the target folder.


Question: How to detect the request by built-in Web Server?
if(php_sapi_name()=='cli-server'){
    echo "this is request by built-in Web Server";
}



Question: Give full working example of built-in Web Server?
  1. Create a file hello.php
  2. Login to command line
  3. Go to that particular folder in command line
  4. Execute following command.
    php -S 0.0.0.0:8080 hello.php
    



Tuesday 19 September 2017

Standard PHP Library (SPL) with Basic details

Standard PHP Library (SPL) with Basic details

Question: What is full form of SPL?
Standard PHP Library.


Question: What is SPL?
It is collection of interfaces and Classes.


Question: Do we need to download library for SPL?
No, We need not to download external library.


Question: What does provide SPL?
SPL provides following Iterators, Interface and Functions.
  1. Set of standard Data Structure.
  2. a Iterators to traverse over objects
  3. Set of Interfaces
  4. Set of standard Exceptions
  5. SPL Functions
  6. SPL File Handling



Question: What classes are available in SPL data structure?
Doubly Linked Lists: It is a list of nodes linked in both directions to each other. Iterator operations, access to both end node, addition or removal of nodes.
http://php.net/manual/en/class.spldoublylinkedlist.php

Heaps: Heaps are tree-like structures that follow the General heap, each node is greater than or equal to its children.
http://php.net/manual/en/class.splheap.php

Arrays: Arrays are structures that store the data in a continuous way, accessible via indexes.
http://php.net/manual/en/class.splfixedarray.php

Map: A map is a datastructure holding key-value pairs. PHP arrays can be seen as maps from integers/strings to values.
http://php.net/manual/en/class.splobjectstorage.php



Question: What Iterators classes are available in SPL?
  1. AppendIterator
  2. ArrayIterator
  3. CachingIterator
  4. CallbackFilterIterator
  5. DirectoryIterator
  6. EmptyIterator
  7. FilesystemIterator
  8. FilterIterator
  9. GlobIterator
  10. InfiniteIterator
  11. IteratorIterator
  12. LimitIterator
  13. MultipleIterator
  14. NoRewindIterator
  15. ParentIterator
  16. RecursiveArrayIterator
  17. RecursiveCachingIterator
  18. RecursiveCallbackFilterIterator
  19. RecursiveDirectoryIterator
  20. RecursiveFilterIterator
  21. RecursiveIteratorIterator
  22. RecursiveRegexIterator
  23. RecursiveTreeIterator
  24. RegexIterator



Question: What Interfaces are available in SPL?
  1. Countable
  2. OuterIterator
  3. RecursiveIterator
  4. SeekableIterator
  5. SplObserver
  6. SplSubject



Question: What Exception classes are available in SPL?
  1. BadFunctionCallException
  2. BadMethodCallException
  3. DomainException
  4. InvalidArgumentException
  5. LengthException
  6. LogicException
  7. OutOfBoundsException
  8. OutOfRangeException
  9. OverflowException
  10. RangeException
  11. RuntimeException
  12. UnderflowException
  13. UnexpectedValueException



Question: What are the advantage of iterators?
  1. Laziness: the data is only fetched when you actually need it.
  2. Reduced memory usage: SPL iterators encapsulate the list and expose visibility to one element at a time making them far more efficient.



Question: Give an example of Iterating Arrayst?
  
$arr = array("One", "Two", "three", "Four", "Five", "Six");
$iter = new ArrayIterator($arr);
foreach ($iter as $key => $value) {
    echo $key . ":  " . $value ;
}

Output
  
0: One
1: Two
2: three
3: Four
4: Five
5: Six



Question: Give an example of Iterating Directory Listings?
  
$dir = new DirectoryIterator("/");
foreach ($dir as $item) {
    echo $item . "
";
}

Output
  
$RECYCLE.BIN
Backup
banner
blog backup
data
data.log.txt
desktop files
doremon
mm
mongodb



Question: Give an example of Iterating Directory Recursively?
  
$iter = new RecursiveDirectoryIterator("/");
foreach (new RecursiveIteratorIterator($iter) as $item) {
    echo $item . "
";
}



Wednesday 28 December 2016

How to install redis on wamp server?

How to install redis on wamp server?

Question: What is Redis?
it is an open source advanced key-value database storage system like NoSQL.


Question: Why Redis is used?
Redis is used for caching to speed up application.


Question: How redis helpful in Optimization?
Redis operations can be executed on the server side and reduce the client's workload.


Question: What type of data can be stored in Redis server?
Redis store complex data structures like strings, hashes, lists, sets, sorted sets, bitmaps and hyperlogs as its key values.


Question: Why redis is fast?
Redis is inherently fast as it stores data in memory.


Question: How to install redis in wampserver?
  1. Download the redis
       A) Download Redis setup For 32 Bit System and Install
       B) Download Redis Setup for 64 Bit system and follow below steps.    
    1. Extract the zip file
    2. Place the unzip file in c:\redis
    3. Run redis-server.exe from c:\redis
    4. then Run redis-cli.exe from c:\redis
  2. Check out your php version and know whether thread safety is enabled or not(by using phpinfo()).
  3. Now we need to download the php_redis.dll. Download the php_redis.dll from PECL.
    Download as per PHP Version and thread based.
  4. Extract the zip file.
  5. Copy the php_redis.dll and paste to following folder in Wamp Server.
    wamp\bin\php\php5.x.xx\ext\
  6. Add the following line in your php.ini
    extension=php_redis.dll
  7. Re-start the wamp Server.
  8. Do phpinfo() and search redis. It will start displaying which means its Redis is installed
  9. Learn and Work with redis.



Question: How to check redis is installed Or Not?
try {
    $redis = new Redis();
    $redis->connect('localhost', 6379);
    $redis->set('name', 'Redis is Installed');
    echo $glueStatus = $redis->get('name');
    
} catch (Exception $ex) {
    echo $ex->getMessage();
}